diff --git a/source-map-support.js b/source-map-support.js index 7500296..5c5c752 100644 --- a/source-map-support.js +++ b/source-map-support.js @@ -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; diff --git a/test.js b/test.js index 5d3f928..3a4f83c 100644 --- a/test.js +++ b/test.js @@ -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 */ });',