php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30971 Random highlight_string() bug while handling legal backslash characters
Submitted: 2004-12-03 00:56 UTC Modified: 2005-08-28 01:00 UTC
Votes:9
Avg. Score:4.7 ± 0.7
Reproduced:9 of 9 (100.0%)
Same Version:5 (55.6%)
Same OS:6 (66.7%)
From: jed@php.net Assigned:
Status: No Feedback Package: Strings related
PHP Version: 5CVS, 4CVS OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2004-12-03 00:56 UTC] jed@php.net
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)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-19 11:49 UTC] sniper@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2005-08-20 11:20 UTC] jed@php.net
I provided a working example and screenshots of both results. _Last December_. I got tired of maintaining my labs. subdomain just so these links wouldn't break. Since I hadn't heard anything on this bug I assumed nobody was going to do anything about it, so I stopped caring and went ahead and cleaned up the subdomain.

This behavior exhibits itself regardless of the containing script and is not reliably reproducable (hence the purpose of the screenshots). It's random, and does not matter in its context:

    highlight_string("\n");

...would randomly exhibit this behavior depending on the setup.

I verified this as a CVS developer last year, I'm tired of the jaw-droppingly arrogant support here (from deleting 'irrelevant' comments to ignoring functionality bugs), so I left it to the PHP developers to do something about it.

Plopping a quick fix on this bug and looking for *another* reproduce script won't fix anything. I gave you all you need last December.

If you want the screenshots e-mail me, I'm sure I have them buried somewhere.
 [2005-08-28 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Nov 28 05:03:12 2021 UTC