Gestern durch nen Zufall mitbekommen, dass es keinen Fatal Error gibt,
wenn man beim Verketten am Ende kein Semikolon setzt
und die nächste Operation zB eine Zuweisung ist.
Bsp:
PHP
$string = 'string';
$public_str = 'This is a very long ' . $string . '.' .
' So I chained the ' . $string . ' on multiple lines' .
' and f***ed it up! The ' . $string . ' is not completed by a semicolon.' .
//' Because i commented out this line.';
//while(0){} // parse error/syntax error
//foreach(array()as $arr){} // parse error/syntax error
//for(;;); // parse error/syntax error
// ...
$private_pw = 'pa$$w0rd'; // kein parse error, denn hier wird der wert aus $private_pw angehangen!
echo $public_str;
// This is a very long string. So I chained the string on multiple lines and f***ed it up! The string is not completed by a semicolon.pa$$w0rd
Alles anzeigen
Man beachte:
Zitat... is not completed by a semicolon.pa$$w0rd
pa$$w0rd wäre jetzt direkt ausgegeben.
Jemand ne Idee, wie man sowas per regex o.ä. in Scripten suchen kann?
EDIT:
hab da was:
PHP
$str = "
// test comment
\$string = 'string';
\$public_str = 'This is a very long ' . \$string . '.' .
' So I chained the ' . \$string . ' on multiple lines' .
' and f***ed it up! The ' . \$string . ' is not completed by a semicolon.' .
//' Because i commented out this line.';
//while(0){} // parse error/syntax error
//foreach(array()as \$arr){} // parse error/syntax error
//for(;;); // parse error/syntax error
// ...
\$private_pw = 'pa\$\$w0rd'; // kein parse error, denn hier wird der wert aus \$private_pw angehangen!
";
preg_match_all('/(\/{2,}|\/\*|#).+;/', $str, $matches, PREG_SET_ORDER);
/* pattern:
/
(
\/{2,} -- // (2 or more of a / )
| -- or
\/\* -- /*
| -- or
# -- #
)
.+ -- one or more of any character
; -- semikolon commented out
/
*/
foreach($matches as $match){
echo $match[0] . PHP_EOL;
}
Alles anzeigen
output
Allerding wird jedes aukommentierte Semikolon gefunden.
Suche gerade nach einer Möglichkeit, dass man auskommentierte Semikolons findet auf die eine Zuweisung folgt.