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

fix js exception due to regex flags #8887

Closed
wants to merge 1 commit into from

Conversation

mroch
Copy link
Contributor

@mroch mroch commented May 29, 2022

Summary:
in ESTree, the value property of a regex is an instantiated RegExp object. if it can't be represented for some reason, the value should be null. there is also a regex property with the pattern and flags as strings so you can still tell what it was.

JSON doesn't have regexes, so flow ast already returns null. flow_parser.js runs in a JS engine so it does try to create a RegExp. when creating a RegExp fatals, we previously tried to recover in a bogus way. it should return null instead.

this fixes a crash when the browser engine doesn't support the latest regex flags, like y, u or d.

Fixes #8886

Changelog: [parser] Fix a runtime exception when parsing regexes via the JS version of the parser

Differential Revision: D36754295

Summary:
in ESTree, the `value` property of a regex is an instantiated `RegExp` object. if it can't be represented for some reason, the `value` should be `null`. there is also a `regex` property with the pattern and flags as strings so you can still tell what it was.

JSON doesn't have regexes, so `flow ast` already returns null. `flow_parser.js` runs in a JS engine so it does try to create a `RegExp`. when creating a `RegExp` fatals, we previously tried to recover in a bogus way. it should return `null` instead.

this fixes a crash when the browser engine doesn't support the latest regex flags, like `y`, `u` or `d`.

Fixes facebook#8886

Changelog: [parser] Fix a runtime exception when parsing regexes via the JS version of the parser

Differential Revision: D36754295

fbshipit-source-id: 18ed0bd17f1265a4da3e241e8f3b08fa5b15b722
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D36754295

@fisker
Copy link

fisker commented May 30, 2022

I'm not sure if we have the same problem with BigInt, it should work the same way, eg the BigInt is too big.

@mroch
Copy link
Contributor Author

mroch commented May 30, 2022

looks like we don't even try to create a value for bigint :/

node ?comments "BigIntLiteral" loc [("value", null); ("bigint", string raw)]

filed #8888 for this

@mroch mroch deleted the export-D36754295 branch May 31, 2022 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error thrown when parsing regexp with d flag on Node.js v10
3 participants