Menu

#2143 PHP syntax highlighting: Apostophes within comments after literal token

Bug
closed-fixed
nobody
5
2021-09-22
2019-11-26
No

The lexer for PHP syntax highlighter doesn't end a literal token when a comment is started.
Apostrophes in the comment are therefore considered part of a string literal and need to be paired.

Test case:

<?php

$foo = 0/*'*/;

Discussion

  • Neil Hodgson

    Neil Hodgson - 2019-11-27
    • labels: PHP, Scintilla --> PHP, Scintilla, lexer
    • Priority: 7 --> 5
     
  • Neil Hodgson

    Neil Hodgson - 2019-11-27

    This patch appears to fix the issue but it should be thoroughly checked by someone with more PHP experience than me.

    diff -r a9a0edc8f2f2 lexers/LexHTML.cxx
    --- a/lexers/LexHTML.cxx    Tue Nov 26 09:09:26 2019 +1100
    +++ b/lexers/LexHTML.cxx    Wed Nov 27 11:52:31 2019 +1100
    @@ -2304,13 +2304,15 @@
            case SCE_HPHP_NUMBER:
                // recognize bases 8,10 or 16 integers OR floating-point numbers
                if (!IsADigit(ch)
                    && strchr(".xXabcdefABCDEF", ch) == NULL
                    && ((ch != '-' && ch != '+') || (chPrev != 'e' && chPrev != 'E'))) {
                    styler.ColourTo(i - 1, SCE_HPHP_NUMBER);
    
    -               if (IsOperator(ch))
    +               if (ch == '/' && chNext == '*')
    +                   state = SCE_HPHP_COMMENT;
    +               else if (IsOperator(ch))
                        state = SCE_HPHP_OPERATOR;
                    else
                        state = SCE_HPHP_DEFAULT;
                }
                break;
            case SCE_HPHP_VARIABLE:
    
     
    • Zufu Liu

      Zufu Liu - 2019-11-27

      at least SCE_HPHP_COMMENTLINE is missing as in above SCE_HPHP_WORD, possible the entire case SCE_HPHP_NUMBER can be removed, this is the only case that handles number, other scripts only has case xxx__WORD, and mostly works except for exponent like

      <script>
      var a = 1.23e-4; /* +- not highlighted as number */
      </script>
      
       
      • Neil Hodgson

        Neil Hodgson - 2020-02-01

        This doesn't appear to be about PHP. For PHP, this sample lexes with '-' as number:

        <?php
        var a = 1.23e-4; /* +- not highlighted as number */
        ?>
        
         
        • Dejan Budimir

          Dejan Budimir - 2020-02-01

          It's javascript (says <script> not <?php). Threw me off as well at first. I think I've fixed it with my patch. (And I've applied your principle of minimal change though I really wanted to rewrite some things, but meh.)

           

          Last edit: Dejan Budimir 2020-02-01
  • Dejan Budimir

    Dejan Budimir - 2020-01-31

    This should work. Based on Neil's patch. Cheers.

     
  • Neil Hodgson

    Neil Hodgson - 2020-02-03

    Added test case [a299df].

    First hunk of LexHTML.cxx.patch does not appear to be connected to this bug.

     

    Related

    Commit: [a299df]

    • Dejan Budimir

      Dejan Budimir - 2020-02-03

      Should I split the patch up and create another ticket for the JavaScript bug?

       
      • Neil Hodgson

        Neil Hodgson - 2020-02-03

        Each bug should be a separate issue on the tracker and should have a test case in lexilla/test/examples.

         
  • Neil Hodgson

    Neil Hodgson - 2021-08-02
    • status: open --> open-fixed
     
  • Neil Hodgson

    Neil Hodgson - 2021-08-02

    Fix committed with Lexilla issue #20.
    https://github.com/ScintillaOrg/lexilla/issues/20

     
  • Neil Hodgson

    Neil Hodgson - 2021-09-22
    • status: open-fixed --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB