File tree 2 files changed +30
-3
lines changed 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,9 @@ var fileContentsCache = {};
14
14
// Maps a file path to a source map for that file
15
15
var sourceMapCache = { } ;
16
16
17
+ // Regex for detecting source maps
18
+ var reSourceMap = / ^ d a t a : a p p l i c a t i o n \/ j s o n [ ^ , ] + b a s e 6 4 , / ;
19
+
17
20
function isInBrowser ( ) {
18
21
return ( ( typeof window !== 'undefined' ) && ( typeof XMLHttpRequest === 'function' ) ) ;
19
22
}
@@ -97,10 +100,10 @@ function retrieveSourceMap(source) {
97
100
98
101
// Read the contents of the source map
99
102
var sourceMapData ;
100
- var dataUrlPrefix = "data:application/json;base64," ;
101
- if ( sourceMappingURL . slice ( 0 , dataUrlPrefix . length ) . toLowerCase ( ) == dataUrlPrefix ) {
103
+ if ( reSourceMap . test ( sourceMappingURL ) ) {
102
104
// Support source map URL as a data url
103
- sourceMapData = new Buffer ( sourceMappingURL . slice ( dataUrlPrefix . length ) , "base64" ) . toString ( ) ;
105
+ var rawData = sourceMappingURL . slice ( sourceMappingURL . indexOf ( ',' ) + 1 ) ;
106
+ sourceMapData = new Buffer ( rawData , "base64" ) . toString ( ) ;
104
107
sourceMappingURL = null ;
105
108
} else {
106
109
// Support source map URLs relative to the source URL
Original file line number Diff line number Diff line change @@ -391,3 +391,27 @@ it('missing source maps should also be cached', function(done) {
391
391
'1' , // The retrieval should only be attempted once
392
392
] ) ;
393
393
} ) ;
394
+
395
+ /* The following test duplicates some of the code in
396
+ * `compareStackTrace` but appends a charset to the
397
+ * source mapping url.
398
+ */
399
+ it ( 'finds source maps with charset specified' , function ( ) {
400
+ var sourceMap = createMultiLineSourceMap ( )
401
+ var source = [ 'throw new Error("test");' ] ;
402
+ var expected = [
403
+ 'Error: test' ,
404
+ / ^ a t O b j e c t \. e x p o r t s \. t e s t \( .* \/ l i n e 1 \. j s : 1 0 0 1 : 1 0 1 \) $ /
405
+ ] ;
406
+
407
+ fs . writeFileSync ( '.generated.js' , 'exports.test = function() {' +
408
+ source . join ( '\n' ) + '};//@ sourceMappingURL=data:application/json;charset=utf8;base64,' +
409
+ new Buffer ( sourceMap . toString ( ) ) . toString ( 'base64' ) ) ;
410
+ try {
411
+ delete require . cache [ require . resolve ( './.generated' ) ] ;
412
+ require ( './.generated' ) . test ( ) ;
413
+ } catch ( e ) {
414
+ compareLines ( e . stack . split ( '\n' ) , expected ) ;
415
+ }
416
+ fs . unlinkSync ( '.generated.js' ) ;
417
+ } ) ;
You can’t perform that action at this time.
0 commit comments