Skip to content

RegExp slash escapes not parsed correctly #68

Closed

Description

@cartant

Using the following snippet in the ESQuery demo:

var f = "foo/bar";

None of these queries is parsed correctly and all fail with an error:

[value=/foo\/bar/]

Invalid regular expression: /foo/: \ at end of pattern

[value=/foo\\/bar/]

Expected " " or "]" but "b" found.

[value=/foo\\\\/bar/]

Expected " " or "]" but "b" found.

I'm using tsquery to write an import-location-specific TSLint rule for RxJS and the RegExp issue appears to be an upstream problem with this package.

Activity

  1. michaelficarra commented on Jun 3, 2018

    @michaelficarra
    Member

    Yeah, the regexp parsing leaves a bit to be desired:

    regex = "/" d:[^/]+ "/" { return { type: 'regexp', value: new RegExp(d.join('')) }; }

    We should enhance it to at least take into account escape sequences and character classes.

  2. cartant commented on Jun 3, 2018

    @cartant
    Author

    My situation was easy to work around, so this is not something that's blocking me. I can have a look at it later, if you are interested in a PR to fix the problem.

  3. michaelficarra commented on Jun 3, 2018

    @michaelficarra
    Member

    Sure, send one over.

  4. toefraz commented on Aug 23, 2018

    @toefraz

    As a workaround you can use the unicode code for / in place of the actual character:

    [value=/foo\\u002Fbar/]

  5. colinta commented on Feb 9, 2024

    @colinta

    @toefraz I "optimized" your code. 🤣 [value=/foo\\x2Fbar/] (I am kidding, but also I am flexing my knowledge of obscure JS string parsing)

  6. pke commented on Jun 27, 2024

    @pke

    Will this ever be fixed?

  7. added a commit that references this issue on Jul 30, 2026
  8. added a commit that references this issue on Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions