-
Notifications
You must be signed in to change notification settings - Fork 126
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
workaround for broken Edge versions 15-18 #304
Conversation
Thanks for the bugfix! I appreciate how tricky this is to track down. I'd prefer if we feature detected function flags(re) {
if (re.flags !== undefined) {
return re.flags;
}
return [
re.global ? "g" : "",
re.ignoreCase ? "i" : "",
re.multiline ? "m" : "",
re.unicode ? "u" : "",
re.sticky ? "y" : "",
].join("");
} These boolean properties are supported all the way back to IE 5.5 apparently, so |
Thanks! Looks like you'll need to run prettier After that, you'll need to make the test coverage go back up to 100%. I would suggested modifying a regexp like: var oldRegExp = /a/gimuy;
// Simulate old RegExp without flags property
Object.defineProperty(oldRegExp, "flags", { value: undefined }); |
Sure, I added that instead. I agree the way I tested the 5 boolean flags in my production environment, it looks like Using this regex:
and got this: Mostly just noting this for you if it ever comes up. I doubt it will! As for the tests and whatnot, sure, I can do some of that maybe later in the week. As a suggestion - the README on contributing should mention the linter and/or test coverage expectations. I'd add them but I don't know what the expectations are 😄 |
Good to know, thanks! Old Edge still had some warts for sure.
My bad, I swear I had those covered. I'll add a pull request template with a checklist/info |
https://github.com/jneen/parsimmon/blob/master/PULL_REQUEST_TEMPLATE.md I can edit this if I forgot anything 😄 |
@@ -7,5 +7,8 @@ | |||
"Parsimmon": true, | |||
"assert": true, | |||
"testSetScenario": true | |||
}, | |||
"rules": { | |||
"no-invalid-regexp": ["error", {"allowConstructorFlags": ["u", "y"]}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ESLint doesn't like these flags by default. And this override doesn't work if you define the Regexp like /a/gimuy
, you have to use the new Regexp
constructor, apparently.
@wavebeem alright, I think this should be complete. I added the changelog entries, but I guess it's a bit weird since idk if you'll actually release it with that version number. Let me know if this needs to be squashed or if you'll do that, etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great all around, but I don't think Parsimmon.flags
needs to be exported. I don't think that function will be useful to anyone using Parsimmon.
In order to test this you could do something like:
assert.throws(function() {
Parsimmon.regexp(/a/g);
});
assert.throws(function() {
Parsimmon.regexp(/a/y);
});
assert.doesNotThrow(function() {
Parsimmon.regexp(/a/i);
});
assert.doesNotThrow(function() {
Parsimmon.regexp(/a/m);
});
assert.doesNotThrow(function() {
Parsimmon.regexp(/a/u);
});
// ...and then test the "messed up" regexps with flags set to undefined
Personally I think the test is harder to read / isn't as obviously testing the behavior it is testing this way, and it doesn't test the return value of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel you on the tests being harder to read now, but I don't want to needlessly expand Parsimmonn's already large API.
CHANGELOG.md
Outdated
@@ -1,7 +1,6 @@ | |||
## version 1.16.0 (2020-08-25) | |||
|
|||
- Adds `Parsimmon.flags(regexp)` export | |||
- Fixes `Parsimmon.flags(regexp)` to work in older browsers (Edge versions 15-18) | |||
- Fixes `flags(regexp)` to work in older browsers (Edge versions 15-18), which fixes crashes on startup in those old clients |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could shorten this to Fixes a crash in MS Edge 15-18 when using Parsimmon.regexp
Also feel free to add your github handle to the changelog here as credit if you'd like 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, solved, and thanks!
Looks great! Thanks for your work on this. I'll merge this and release it in a few hours or so. |
@ekilah 1.16.0 is up! https://www.npmjs.com/package/parsimmon |
Awesome 🥳 Thanks for your help debugging & getting this live! |
Fixes #303
npm run lint:fix
to ensure Prettier and ESLint have passednpm test
)CHANGELOG.md
(andAPI.md
if this is an API chSummary of problem
We saw these reports in our bug tracker:
These errors were coming from MS Edge versions 15-18, but I couldn't find a way to download and install that version to test for myself. It seemed like that browser was rendering the literal string
"undefined"
at the end of regular expressions when they were printed as strings.Research
To get some data from our prod environment, I added the following code to
parsimmon
(you can see the fork I used here: master...ekilah:debuggingEdge18):and got this output from Edge versions 17 and 18:
I also added this above
var digit = regexp(/[0-9]/).desc("a digit");
so it would run whenparsimmon
is imported in my project:and got this output from Edge versions 17 and 18:
Fix
To fix this, we can detect
undefined
as theflags
string and overwrite it.