Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to parse mongodb url regular expression #1147

Closed
soufianos01 opened this issue Sep 15, 2022 · 2 comments
Closed

Failed to parse mongodb url regular expression #1147

soufianos01 opened this issue Sep 15, 2022 · 2 comments

Comments

@soufianos01
Copy link

Hi,

while trying to parse a code that connects to a mongodb database, acorn in its latest version has a problem dealing with this regular expression: '^(?<protocol>[^/]+):\\/\\/(?:(?<username>[^:@]*)(?::(?<password>[^@]*))?@)?(?<hosts>(?!:)[^/?@]*)(?<rest>.*)'

Here is the error:

SyntaxError: Invalid regular expression: /^(?<protocol>[^/]+):\/\/(?:(?<username>[^:@]*)(?::(?<password>[^@]*))?@)?(?<hosts>(?!:)[^/?@]*)(?<rest>.*)/: Invalid group (12:21)
    at Parser.pp$4.raise (/mnt/home/usr/Documents/jalangi2/node_modules/acorn/dist/acorn.js:3459:15)
    at RegExpValidationState.raise (/mnt/home/usr/Documents/jalangi2/node_modules/acorn/dist/acorn.js:3705:17)
    at Parser.pp$1.regexp_eatCapturingGroup (/mnt/home/usr/Documents/jalangi2/node_modules/acorn/dist/acorn.js:4013:15)
    at Parser.pp$1.regexp_eatExtendedAtom (/mnt/home/usr/Documents/jalangi2/node_modules/acorn/dist/acorn.js:4032:12)
    at Parser.pp$1.regexp_eatTerm (/mnt/home/usr/Documents/jalangi2/node_modules/acorn/dist/acorn.js:3882:59)
    at Parser.pp$1.regexp_alternative (/mnt/home/usr/Documents/jalangi2/node_modules/acorn/dist/acorn.js:3863:52)
    at Parser.pp$1.regexp_disjunction (/mnt/home/usr/Documents/jalangi2/node_modules/acorn/dist/acorn.js:3847:10)
    at Parser.pp$1.regexp_pattern (/mnt/home/usr/Documents/jalangi2/node_modules/acorn/dist/acorn.js:3822:10)
    at Parser.pp$1.validateRegExpPattern (/mnt/home/usr/Documents/jalangi2/node_modules/acorn/dist/acorn.js:3798:10)
    at Parser.pp.readRegexp (/mnt/home/usr/Documents/jalangi2/node_modules/acorn/dist/acorn.js:5154:10) {
  pos: 656,
  loc: Position { line: 12, column: 21 },
  raisedAt: 763
@marijnh
Copy link
Member

marijnh commented Sep 15, 2022

Can you show how you're testing this? This parses fine:

const { parse } = require('acorn')
const re = '/^(?<protocol>[^/]+):\\/\\/(?:(?<username>[^:@]*)(?::(?<password>[^@]*))?@)?(?<hosts>(?!:)[^/?@]*)(?<rest>.*)/'
console.log(parse(re, {ecmaVersion: "latest"}))

@soufianos01
Copy link
Author

Thanks for your reply! Yes, changing the ecmaVersion to latest solves my problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants