Skip to content

PHP: Escaped quotes not recognised correctly #2105

@Krinkle

Description

@Krinkle

The string is currently terminated after the third quote in "foo \"$bar\" baz" instead of at the end.

Source:

<?php
if ( extension_loaded( 'excimer' ) && isset( $_GET['forceflame'] ) ) {
	$prof = new ExcimerProfiler();
	$prof->setPeriod( 0.1 / 1000 ); // Every 0.1ms
	$prof->setEventType( EXCIMER_REAL );
	$prof->start();
	register_shutdown_function( function () use ( $prof ) {
		$prof->stop();
		$title = MW_ENTRY_POINT . '.php ' . gmdate( 'Y-m-d H:i:s' ) . ' UTC';
		$pipe = popen( "/usr/local/bin/flamegraph.pl --title=\"$title\" > /var/www/html/w/docs/flamegraph.svg", 'w' );
		fwrite( $pipe, $prof->getLog()->formatCollapsed() );
	} );
}

Pygments:

Screenshot 2022-04-06 at 00 00 47

Downstream: https://www.mediawiki.org/w/index.php?title=MediaWiki-Docker/Configuration_recipes/Profiling&oldid=5148799

Minimal demo:

<?php
$title = 'UTC';
$pipe = popen( "flamegraph.pl --title=\"$title\" > /var/www/html/w/docs/flamegraph.svg", 'w' );
fwrite( $pipe, $prof->getLog()->formatCollapsed() );

Screenshot 2022-04-06 at 00 38 41

https://pygments.org/demo/?lexer=php&style=xcode&formatter=html&code=%3C%3Fphp%0A%24title+%3D+%27UTC%27%3B%0A%24pipe+%3D+popen%28+%22flamegraph.pl+--title%3D%5C%22%24title%5C%22+%3E+%2Fvar%2Fwww%2Fhtml%2Fw%2Fdocs%2Fflamegraph.svg%22%2C+%27w%27+%29%3B%0Afwrite%28+%24pipe%2C+%24prof-%3EgetLog%28%29-%3EformatCollapsed%28%29+%29%3B

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions