Skip to content

Commit

Permalink
Add support for utf8 name in input source map encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed May 2, 2016
1 parent 65def66 commit 215ed88
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/previous-map.es6
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ export default class PreviousMap {
}

decodeInline(text) {
let utf64 = 'data:application/json;charset=utf-8;base64,';
let b64 = 'data:application/json;base64,';
let uri = 'data:application/json,';
let utfd64 = 'data:application/json;charset=utf-8;base64,';
let utf64 = 'data:application/json;charset=utf8;base64,';
let b64 = 'data:application/json;base64,';
let uri = 'data:application/json,';

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

} else if ( this.startWith(text, utfd64) ) {
return Base64.decode( text.substr(utfd64.length) );

} else {
let encoding = text.match(/data:application\/json;([^,]+),/)[1];
throw new Error('Unsupported source map encoding ' + encoding);
Expand Down
8 changes: 8 additions & 0 deletions test/previous-map.es6
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ describe('PreviousMap', () => {
expect(parse(css).source.input.map.text).to.eql(map);
});

it('accepts different name for UTF-8 encoding', () => {
let b64 = new Buffer(map).toString('base64');
let css = 'a{}\n/*# sourceMappingURL=data:application/json;' +
'charset=utf8;base64,' + b64 + ' */';

expect(parse(css).source.input.map.text).to.eql(map);
});

it('decodes URI maps', () => {
let uri = 'data:application/json,' + decodeURI(map);
let css = `a{}\n/*# sourceMappingURL=${ uri } */`;
Expand Down

0 comments on commit 215ed88

Please # to comment.