Skip to content

Conversation

@tromey
Copy link
Contributor

@tromey tromey commented Sep 25, 2017

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

Copy link

@julienw julienw left a 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(")]}'")) {
Copy link

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

Copy link

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.

Copy link

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.

Copy link
Contributor Author

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(/^\)\]\}'/, ''));
Copy link

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.

Copy link
Contributor Author

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);
Copy link

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.

Copy link
Contributor Author

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;
Copy link

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;
Copy link

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" ?

@tromey tromey force-pushed the json-xssi-avoidance branch from b3d026b to 54e79b8 Compare September 25, 2017 16:49
lib/util.js Outdated
* JSON.
*/
function parseSourceMapInput(str) {
return JSON.parse(str.replace(/^\)]}'(?:[^\n]*?\n)/, ''));
Copy link

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 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, duh. Thanks.

Copy link

@julienw julienw left a 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
@tromey tromey force-pushed the json-xssi-avoidance branch from 54e79b8 to de68f7f Compare September 26, 2017 13:41
@tromey tromey merged commit 1941aaa into mozilla:master Sep 26, 2017
@tromey tromey deleted the json-xssi-avoidance branch September 26, 2017 13:47
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

Successfully merging this pull request may close these issues.

2 participants