-
Notifications
You must be signed in to change notification settings - Fork 366
Remove entire first line when JSON XSSI prevention seen #283
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
Conversation
julienw
left a comment
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 have some conflicts with current master, I believe you'll need to rebase and regenerate the dist files.
I put r- because the tests fail in node <= 0.12. Otherwise I left some nits that you're free to approve or ignore :)
lib/util.js
Outdated
| * JSON. | ||
| */ | ||
| function parseJSON(str) { | ||
| if (str.startsWith(")]}'")) { |
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.
startsWith fails in node 0.10/0.12, sadly: https://travis-ci.org/mozilla/source-map/builds/279505665
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 wouldn't mind to stop supporting these versions but then I think you'll need a major version change.
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'd reuse the previous regexp to do this as a replacement.
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'm planning a major version bump anyhow, due to other pending PRs.
0.10 was still seeing new releases last year; so, ugh, I guess we carry on.
| function SourceMapConsumer(aSourceMap) { | ||
| var sourceMap = aSourceMap; | ||
| if (typeof aSourceMap === 'string') { | ||
| sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); |
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.
note: if you reuse the same regexp (see below), please note that only the parens needs escaping.
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 did do it this way fwiw.
lib/util.js
Outdated
| // No line, return nothing. | ||
| return null; | ||
| } | ||
| str = str.substring(index + 1); |
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.
Wondering if we should then assert that the source map format revision is > 3. I think we don't need to, but it's your call.
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 that's done elsewhere.
lib/util.js
Outdated
| var index = str.indexOf("\n"); | ||
| if (index < 0) { | ||
| // No line, return nothing. | ||
| return null; |
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'd rather throw an error, just like JSON.parse throws an error if there is no input.
lib/util.js
Outdated
| } | ||
| return JSON.parse(str); | ||
| } | ||
| exports.parseJSON = parseJSON; |
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.
nitpicking: I don't like the name as it looks like the only thing it does is parsing JSON :) Maybe "parseSourceMapInput" ?
b3d026b to
54e79b8
Compare
lib/util.js
Outdated
| * JSON. | ||
| */ | ||
| function parseSourceMapInput(str) { | ||
| return JSON.parse(str.replace(/^\)]}'(?:[^\n]*?\n)/, '')); |
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.
Some simplifications:
- You don't need the grouping :)
- you don't need the ungreedy variant
*?thanks to your character class
so I think /^\)]}'[^\n]*\n/ works fine and is simpler :)
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.
Yes, duh. Thanks.
julienw
left a comment
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.
Let's go, but with the simpler version of the regexp :)
The source map specification says that the entire first line should be removed when the source map string starts with the JSON XSSI preventing string. Fixes mozilla#278
54e79b8 to
de68f7f
Compare
The source map specification says that the entire first line should be
removed when the source map string starts with the JSON XSSI preventing
string.
Fixes #278