From: jed at jed dot bz Operating system: * PHP version: Irrelevant PHP Bug Type: Unknown/Other Function Bug description: highlight_string chokes bad when parsing strings containing newline escapes
Description: ------------ Bug 25725 was marked bogus due to a bad example. I am reopening it here because this is a particularly annoying bug that needs to be fixed, regardless of 'this is not an issue' sentiment within the PHP community. When the highlight_string() engine encounters ANY \ character, even one prefixing an escape like \n (which are LEGAL, as some astute Quick Fix posters have ignored), the parser interjects warnings into highlight_string()'s output. The catch? This only happens randomly. We rely on highlight_string() for our IRC pastebin, and I am sure this function is used a lot elsewhere. I have submitted another entry to our pastebin and was quite disappointed to see the bug's problem at once: http://labs.jed.bz/phpbug3.png Screenshot taken from http://dalphp.shoggoth.net/pastebin_view.php?533 I have highlighted the problem for the QA reviewers with itchy Quick Fix fingers. Notice the 'n' sitting on a line all by itself? That's the back end of a \n sequence, and the PHP parser is erring on the \ itself. It's as if the tokenizer, when used under highlight_string(), isn't glomming \ onto its following character. It is also only doing it on some newlines. As you can see, the newlines next to '019' (the bottom of the highlight) are parsed fine! As you can also see, the colors in the rest of the code, even on keywords that should be highlighted green like 'static' and 'function', are all messed up. This isn't the first time we've run into this. I've taken screenshots to append to Bug 25725, but they were ignored as well. I rewind and replay them here for community benefit. CORRECT: http://labs.jed.bz/phpbug2.png NOT: http://labs.jed.bz/phpbug.png Source URL: http://dalphp.shoggoth.net/pastebin_view.php?356 Nothing changed on the server between these two requests. I just refreshed until the output changed. And these are legal newlines. The example on Bug 25725 brought the itchy Quick Fix fingers out, but the submitter presented a valid point, which I reiterate here. Highlighted fine: $x = 0 $y = 1 $z = 2 Not highlighted fine: $x = 0; \; $z = 2; And as I've demonstrated, this isn't highlighted fine either: printf("\n"); The randomness of this problem suggests a leak or black magic within PHP itself, and I have a gut feeling this is a little more problematic than it appears at first hand. The reproduce code below is what is supposed to be highlighted in phpbug3.png. Note: Do not flood dalphp.shoggoth.net with refresh requests, trust my screenshots. Reproduce code: --------------- <?php /** * The beefiest exceptioner evar. */ public static function ErrorHandler(Exception $e) { // FIXME // if(file_exists($e->getFile())) { $line = file($e->getFile()); $line = trim($line[$e->getLine() - 1]); } else $line = "?"; printf("\n\nSTOP. Uncaught exception \"%s\" in %s:%u\n" . " >> %s\n" . " Message: (%u) %s\n Backtrace:\n", get_class($e), $e->getFile(), $e->GetLine(), $line, $e->getCode(), $e->getMessage()); $i = 0; foreach($e->getTrace() as $bt) printf(" (#%u) %s()\n", ++$i, $bt['class'] . $bt['type'] . $bt['function'], $bt['file'], $bt['line']); printf("\n\n"); exit(0xFE); } Expected result: ---------------- http://labs.jed.bz/phpbug4.png Actual result: -------------- http://labs.jed.bz/phpbug3.png (Sporadically) -- Edit bug report at http://bugs.php.net/?id=30971&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=30971&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30971&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30971&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=30971&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=30971&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=30971&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=30971&r=needscript Try newer version: http://bugs.php.net/fix.php?id=30971&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=30971&r=support Expected behavior: http://bugs.php.net/fix.php?id=30971&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=30971&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=30971&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=30971&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=30971&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=30971&r=dst IIS Stability: http://bugs.php.net/fix.php?id=30971&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=30971&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=30971&r=float MySQL Configuration Error: http://bugs.php.net/fix.php?id=30971&r=mysqlcfg