SonarQube JavaScript
  1. SonarQube JavaScript
  2. SONARJS-44

Unable to lex regular expression literal which contains "/"

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0
    • Fix Version/s: 1.1
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Here is an example :

      var r = /[^\\h;m,.\-:/\d]+/gi;
      

        Issue Links

          Activity

          Hide
          Tamas Kende added a comment -

          We also have this problem, is there a chance that it will be fixed soon?

          Show
          Tamas Kende added a comment - We also have this problem, is there a chance that it will be fixed soon?
          Hide
          Evgeny Mandrikov added a comment -

          Hi Tamas,

          Not sooner than a release of a new version
          However there is a workaround, which was described in http://markmail.org/message/tts3lunboc6z3uub : escape slash "/" by using backslash "\", i.e. for given example :

          var r = /[^\\h;m,.\-:\/\d]+/gi;
          
          Show
          Evgeny Mandrikov added a comment - Hi Tamas, Not sooner than a release of a new version However there is a workaround, which was described in http://markmail.org/message/tts3lunboc6z3uub : escape slash "/" by using backslash "\", i.e. for given example : var r = /[^\\h;m,.\-:\/\d]+/gi;
          Hide
          Tamas Kende added a comment -

          Hi Evgeny,

          it is strange to me, the exception is the following:

          Caused by: com.sonar.sslr.impl.LexerException: Unable to lex source code at line : 240 and column : 79 in file : file:/home/project/SRC/js/ThisIsIt.js
           at com.sonar.sslr.impl.Lexer.lex(Lexer.java:140) ~[sslr-core-1.13.jar:na]
           at com.sonar.sslr.impl.Lexer.lex(Lexer.java:95) ~[sslr-core-1.13.jar:na]
           ... 39 common frames omitted
          Caused by: java.lang.IllegalStateException: None of the channel has been able to handle character '\' (decimal value 92) at line 240, column 79
          

          and the problematic line is:

                  var impr = imprtags.toString().match(/[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?;&//=]*)?/ig);
          

          so the problem is around this area:

          {2,256}

          \.[a-z] what do I have to escape here to keep the functionality?

          Thanks

          Tamas

          Show
          Tamas Kende added a comment - Hi Evgeny, it is strange to me, the exception is the following: Caused by: com.sonar.sslr.impl.LexerException: Unable to lex source code at line : 240 and column : 79 in file : file:/home/project/SRC/js/ThisIsIt.js at com.sonar.sslr.impl.Lexer.lex(Lexer.java:140) ~[sslr-core-1.13.jar:na] at com.sonar.sslr.impl.Lexer.lex(Lexer.java:95) ~[sslr-core-1.13.jar:na] ... 39 common frames omitted Caused by: java.lang.IllegalStateException: None of the channel has been able to handle character '\' (decimal value 92) at line 240, column 79 and the problematic line is: var impr = imprtags.toString().match(/[-a-zA-Z0-9@:%_\+.~#?& //=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?;&//=]*)?/ig); so the problem is around this area: {2,256} \. [a-z] what do I have to escape here to keep the functionality? Thanks Tamas
          Hide
          Evgeny Mandrikov added a comment - - edited

          As I said - I belive that you simply can escape slash "/":

          var impr = imprtags.toString().match(/[-a-zA-Z0-9@:%_\+.~#?&\/\/=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?;&\/\/=]*)?/ig);
          
          Show
          Evgeny Mandrikov added a comment - - edited As I said - I belive that you simply can escape slash "/": var impr = imprtags.toString().match(/[-a-zA-Z0-9@:%_\+.~#?&\/\/=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?;&\/\/=]*)?/ig);
          Hide
          Tamas Kende added a comment -

          Yes,
          for some reason I did not realized the first two slashes... sorry, now it works, thanks!!!

          Show
          Tamas Kende added a comment - Yes, for some reason I did not realized the first two slashes... sorry, now it works, thanks!!!
          Hide
          Freddy Mallet added a comment -

          Manually tested !

          Show
          Freddy Mallet added a comment - Manually tested !

            People

            • Assignee:
              Evgeny Mandrikov
              Reporter:
              Evgeny Mandrikov
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: