Skip to content

Commit 215ed88

Browse files
committed
Add support for utf8 name in input source map encoding
1 parent 65def66 commit 215ed88

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/previous-map.es6

+7-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ export default class PreviousMap {
3737
}
3838

3939
decodeInline(text) {
40-
let utf64 = 'data:application/json;charset=utf-8;base64,';
41-
let b64 = 'data:application/json;base64,';
42-
let uri = 'data:application/json,';
40+
let utfd64 = 'data:application/json;charset=utf-8;base64,';
41+
let utf64 = 'data:application/json;charset=utf8;base64,';
42+
let b64 = 'data:application/json;base64,';
43+
let uri = 'data:application/json,';
4344

4445
if ( this.startWith(text, uri) ) {
4546
return decodeURIComponent( text.substr(uri.length) );
@@ -50,6 +51,9 @@ export default class PreviousMap {
5051
} else if ( this.startWith(text, utf64) ) {
5152
return Base64.decode( text.substr(utf64.length) );
5253

54+
} else if ( this.startWith(text, utfd64) ) {
55+
return Base64.decode( text.substr(utfd64.length) );
56+
5357
} else {
5458
let encoding = text.match(/data:application\/json;([^,]+),/)[1];
5559
throw new Error('Unsupported source map encoding ' + encoding);

test/previous-map.es6

+8
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ describe('PreviousMap', () => {
7676
expect(parse(css).source.input.map.text).to.eql(map);
7777
});
7878

79+
it('accepts different name for UTF-8 encoding', () => {
80+
let b64 = new Buffer(map).toString('base64');
81+
let css = 'a{}\n/*# sourceMappingURL=data:application/json;' +
82+
'charset=utf8;base64,' + b64 + ' */';
83+
84+
expect(parse(css).source.input.map.text).to.eql(map);
85+
});
86+
7987
it('decodes URI maps', () => {
8088
let uri = 'data:application/json,' + decodeURI(map);
8189
let css = `a{}\n/*# sourceMappingURL=${ uri } */`;

0 commit comments

Comments
 (0)