Change RegExp to be less greedy (Fixes #87).

This commit is contained in:
Melvin Groenhoff 2015-07-27 15:34:21 +02:00
parent 61e1237d15
commit 976b50fa65
2 changed files with 27 additions and 1 deletions

View File

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

25
test.js
View File

@ -416,6 +416,31 @@ it('finds source maps with charset specified', function() {
fs.unlinkSync('.generated.js');
});
/* The following test duplicates some of the code in
* `compareStackTrace` but appends some code and a
* comment to the source mapping url.
*/
it('allows code/comments after sourceMappingURL', function() {
var sourceMap = createMultiLineSourceMap()
var source = [ 'throw new Error("test");' ];
var expected = [
'Error: test',
/^ at Object\.exports\.test \(.*\/line1\.js:1001:101\)$/
];
fs.writeFileSync('.generated.js', 'exports.test = function() {' +
source.join('\n') + '};//# sourceMappingURL=data:application/json;base64,' +
new Buffer(sourceMap.toString()).toString('base64') +
'\n// Some comment below the sourceMappingURL\nvar foo = 0;');
try {
delete require.cache[require.resolve('./.generated')];
require('./.generated').test();
} catch (e) {
compareLines(e.stack.split('\n'), expected);
}
fs.unlinkSync('.generated.js');
});
it('handleUncaughtExceptions is true with existing listener', function(done) {
var source = [
'process.on("uncaughtException", function() { /* Silent */ });',