Skip to content

Commit d7cee54

Browse files
authored
Merge pull request ben-ng#13 from aMarCruz/master
Support charset in inlined sourcemap
2 parents 5793b85 + 496be06 commit d7cee54

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ validate = function (min, map, srcs) {
5959
// If no map was given, try to extract it from min
6060
if(map == null) {
6161
try {
62-
var re = /\s*\/\/(?:@|#) sourceMappingURL=data:application\/json;base64,(\S*)$/m
62+
var re = /\s*\/\/(?:@|#) sourceMappingURL=data:application\/json;(?:charset=utf-?8;)?base64,(\S*)$/m
6363
, map = min.match(re);
6464

6565
map = createBuffer(map[1], 'base64').toString();

tests/unit.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,26 @@ tests['Valid Minifyified bundle with inline sourcemap should not throw'] = funct
9292
}, 'Valid Minifyified inline sourcemap and inline sourceContent should not throw');
9393
};
9494

95+
tests['Valid Minifyified bundle with inline sourcemap and charset should not throw'] = function () {
96+
var mfDir = path.join(validDir, 'Minifyified')
97+
, min = fs.readFileSync(path.join(mfDir, 'bundle.min.js')).toString()
98+
.replace('/json;base64,', '/json;charset=utf-8;base64,');
99+
100+
assert.doesNotThrow(function () {
101+
validate(min);
102+
}, 'Valid Minifyified inline sourcemap and inline sourceContent should not throw');
103+
};
104+
105+
tests['Valid Minifyified bundle with charset without hyphen should not throw'] = function () {
106+
var mfDir = path.join(validDir, 'Minifyified')
107+
, min = fs.readFileSync(path.join(mfDir, 'bundle.min.js')).toString()
108+
.replace('/json;base64,', '/json;charset=utf8;base64,');
109+
110+
assert.doesNotThrow(function () {
111+
validate(min);
112+
}, 'Valid Minifyified inline sourcemap and inline sourceContent should not throw');
113+
};
114+
95115
tests['Valid Babel map should not throw'] = function () {
96116
var babelDir = path.join(validDir, 'Babel')
97117
, map = fs.readFileSync(path.join(babelDir, 'router.js.map')).toString();

0 commit comments

Comments
 (0)