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

master
Melvin Groenhoff 9 years ago
parent 61e1237d15
commit 976b50fa65

@ -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;

@ -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 */ });',

Loading…
Cancel
Save