Menu

#746 Javascript regex breaks symbol list

v1.23
closed-fixed
Filetypes (68)
5
2012-10-26
2011-08-26
Anonymous
No

A regular expression like str.replace(/\//g, "-"); (that is: replace all forward slashes with "-") inside a function definition breaks the function list in the symbols sidebar.
The function with the regex and all following functions vanish from the sidebar.
A regex like str.replace(/(\/)/g, "-") works. So the problem is that there is nothing but (one or more) slashes in the regex.
Geany 0.21 (svn >= 5888) Windows XP, german
(kompiliert am Aug 16 2011 oder später)

Related

Bugs: #981

Discussion

  • Nobody/Anonymous

    test.js to show the error with javascript regex

     
  • Nobody/Anonymous

    SciTE 2.01 and SciTE 2.29 properly highlight the regular expression.
    PSPad 4.5.4 (another Scintilla based editor) properly shows the function list.
    Geany 0.19 svn >= 4375 also breaks the function list.
    The regular expression definitely is valid.

     
  • Josh

    Josh - 2011-10-03

    I can confirm this on windows 7 with geany 0.21

     
  • Nick Treleaven

    Nick Treleaven - 2011-10-04
    • assigned_to: nobody --> ntrel
     
  • Colomban Wendling

    @nick: The reason why this happens is because the JS parser don't recognize regexp, and then treats "//" in it as a single-line comment start. Doing so eats the closing brace at the end of the line, thus making the parser search it 'til the end of file.

    A proper fix would probably be to properly read the regex, though I'm not sure how do to so (e.g. it needs to differentiate division from re start, etc.).

     
  • Nick Treleaven

    Nick Treleaven - 2011-10-04
     
  • Nick Treleaven

    Nick Treleaven - 2011-10-04
    • assigned_to: ntrel --> nobody
     
  • Nick Treleaven

    Nick Treleaven - 2011-10-04

    @ban: I've attached a simple fix that works (fix-js-regex-escape.diff), but I don't know if it causes other problems. Single line comments still seem to be ignored AFAICT. Let me know if this is OK.

     
  • Colomban Wendling

    @nick: I don't know JS very well, but yes I think this will fix (or workaround) the exact problem the reporter had since a "/" must be escaped in a RE. However, it won't catch other syntactic starts in a RE, e.g. strings: str.replace(/"/, """) will still confuse the parser.

    Actually it'd need probably a "real" (or partial at least) RE parser to catch all cases, because even the regex /[//]/ is perfectly valid. OK, it's stupid, but totally acceptable syntactically. Not sure it worth it though.

     
  • Nick Treleaven

    Nick Treleaven - 2011-10-04

    @codebrainz: I updated js.c from CTags SVN jscript.c early this afternoon. It still doesn't parse regexes, but we now have many other fixes.

    @ban: You're right that a proper fix needs to parse regexes - I won't commit my diff for this reason.

    If anyone feels like filing a CTags bug for JS regex support, please go ahead.

     
  • Colomban Wendling

    • milestone: --> v1.23
    • assigned_to: nobody --> colombanw
    • status: open --> closed-fixed
     
  • Colomban Wendling

    Now fixed in Git, thanks for reporting.

     

Log in to post a comment.