#1415 JavaScript regex doesn't properly handle character ranges

Bug
closed-fixed
Neil Hodgson
Scintilla (789)
5
2013-01-17
2012-10-26
No

When parsing JavaScript regular expression, character ranges ([...]) aren't took into account, resulting in improper termination of the regex if the range includes the delimiter.

For example, regular expression "/[/]/" is perfectly valid, the second "/" being escaped by the character range.

Patch attached.

Discussion

  • Neil Hodgson
    Neil Hodgson
    2012-10-26

    I won't be looking at this until the new year.

     
  • Neil Hodgson
    Neil Hodgson
    2012-10-26

    • assigned_to: nobody --> nyamatongwe
     
  • Neil Hodgson
    Neil Hodgson
    2012-12-30

    Since this is using a local variable initialised at the start of the lexed block but not reset at the start of each line, it appears as if it would be possible to produce different results depending on which lines are lexed together. The bare sc.Forward() after '\' also appears dangerous: what happens if there is a line end after the '\'?

     
  • Neil Hodgson
    Neil Hodgson
    2012-12-30

    • status: open --> open-accepted
     
  • Revised patch attached.

    > Since this is using a local variable initialised at the start of the lexed
    > block but not reset at the start of each line, it appears as if it would
    > be possible to produce different results depending on which lines
    > are lexed together.

    Actually no, because the flag is reset when entering a RE and the RE state is left at the start of a the line. However it's indeed clearer if reset unconditionally, so I fixed this.

    > The bare sc.Forward() after '\' also appears dangerous: what
    > happens if there is a line end after the '\'?

    Right, maybe it'd break something. I added a check to eat everything but '\r' and '\n'.

     
  • Neil Hodgson
    Neil Hodgson
    2012-12-30

    • status: open-accepted --> open-fixed
     
  • Neil Hodgson
    Neil Hodgson
    2012-12-30

    Committed.

     
  • Neil Hodgson
    Neil Hodgson
    2013-01-17

    • status: open-fixed --> closed-fixed