Skip to content

Commit 6296f61

Browse files
committed
Merge pull request #88 from Ravoltz/master
Change RegExp to be less greedy (Fixes #87).
2 parents 61e1237 + 976b50f commit 6296f61

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

source-map-support.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ function retrieveSourceMapURL(source) {
8484

8585
// Get the URL of the source map
8686
fileData = retrieveFile(source);
87-
var re = /\/\/[#@]\s*sourceMappingURL=([^'"]+)\s*$/mg;
87+
// //# sourceMappingURL=foo.js.map /*# sourceMappingURL=foo.js.map */
88+
var re = /(?:\/\/[@#][ \t]+sourceMappingURL=([^\s'"]+?)[ \t]*$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^\*]+?)[ \t]*(?:\*\/)[ \t]*$)/mg;
8889
// Keep executing the search to find the *last* sourceMappingURL to avoid
8990
// picking up sourceMappingURLs from comments, strings, etc.
9091
var lastMatch, match;

test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,31 @@ it('finds source maps with charset specified', function() {
416416
fs.unlinkSync('.generated.js');
417417
});
418418

419+
/* The following test duplicates some of the code in
420+
* `compareStackTrace` but appends some code and a
421+
* comment to the source mapping url.
422+
*/
423+
it('allows code/comments after sourceMappingURL', function() {
424+
var sourceMap = createMultiLineSourceMap()
425+
var source = [ 'throw new Error("test");' ];
426+
var expected = [
427+
'Error: test',
428+
/^ at Object\.exports\.test \(.*\/line1\.js:1001:101\)$/
429+
];
430+
431+
fs.writeFileSync('.generated.js', 'exports.test = function() {' +
432+
source.join('\n') + '};//# sourceMappingURL=data:application/json;base64,' +
433+
new Buffer(sourceMap.toString()).toString('base64') +
434+
'\n// Some comment below the sourceMappingURL\nvar foo = 0;');
435+
try {
436+
delete require.cache[require.resolve('./.generated')];
437+
require('./.generated').test();
438+
} catch (e) {
439+
compareLines(e.stack.split('\n'), expected);
440+
}
441+
fs.unlinkSync('.generated.js');
442+
});
443+
419444
it('handleUncaughtExceptions is true with existing listener', function(done) {
420445
var source = [
421446
'process.on("uncaughtException", function() { /* Silent */ });',

0 commit comments

Comments
 (0)