From 1f852ed747f2e5aedc2c1712da91ec2c09e8177e Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Tue, 20 Oct 2020 13:11:52 -0700 Subject: [PATCH] Percent-encode source map URLs (#41102) --- src/compiler/emitter.ts | 17 +++-- .../reference/sourceMapPercentEncoded.js | 10 +++ .../reference/sourceMapPercentEncoded.js.map | 3 + .../sourceMapPercentEncoded.sourcemap.txt | 76 +++++++++++++++++++ .../reference/sourceMapPercentEncoded.symbols | 10 +++ .../reference/sourceMapPercentEncoded.types | 13 ++++ .../cases/compiler/sourceMapPercentEncoded.ts | 6 ++ 7 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 tests/baselines/reference/sourceMapPercentEncoded.js create mode 100644 tests/baselines/reference/sourceMapPercentEncoded.js.map create mode 100644 tests/baselines/reference/sourceMapPercentEncoded.sourcemap.txt create mode 100644 tests/baselines/reference/sourceMapPercentEncoded.symbols create mode 100644 tests/baselines/reference/sourceMapPercentEncoded.types create mode 100644 tests/cases/compiler/sourceMapPercentEncoded.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 237d3fee9cd..ee2d1b9c576 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -606,18 +606,19 @@ namespace ts { if (getRootLength(sourceMapDir) === 0) { // The relative paths are relative to the common directory sourceMapDir = combinePaths(host.getCommonSourceDirectory(), sourceMapDir); - return getRelativePathToDirectoryOrUrl( - getDirectoryPath(normalizePath(filePath)), // get the relative sourceMapDir path based on jsFilePath - combinePaths(sourceMapDir, sourceMapFile), // this is where user expects to see sourceMap - host.getCurrentDirectory(), - host.getCanonicalFileName, - /*isAbsolutePathAnUrl*/ true); + return encodeURI( + getRelativePathToDirectoryOrUrl( + getDirectoryPath(normalizePath(filePath)), // get the relative sourceMapDir path based on jsFilePath + combinePaths(sourceMapDir, sourceMapFile), // this is where user expects to see sourceMap + host.getCurrentDirectory(), + host.getCanonicalFileName, + /*isAbsolutePathAnUrl*/ true)); } else { - return combinePaths(sourceMapDir, sourceMapFile); + return encodeURI(combinePaths(sourceMapDir, sourceMapFile)); } } - return sourceMapFile; + return encodeURI(sourceMapFile); } } diff --git a/tests/baselines/reference/sourceMapPercentEncoded.js b/tests/baselines/reference/sourceMapPercentEncoded.js new file mode 100644 index 00000000000..e0b4c7948e3 --- /dev/null +++ b/tests/baselines/reference/sourceMapPercentEncoded.js @@ -0,0 +1,10 @@ +//// [①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].ts] +var a = 1; +var b = 2; +var c = 3; + +//// [①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].js] +var a = 1; +var b = 2; +var c = 3; +//# sourceMappingURL=%E2%91%A0%E2%85%AB%E3%84%A8%E3%84%A9%20%E5%95%8A%E9%98%BF%E9%BC%BE%E9%BD%84%E4%B8%82%E4%B8%84%E7%8B%9A%E7%8B%9B%E7%8B%9C%E7%8B%9D%EF%A8%A8%EF%A8%A9%CB%8A%CB%8B%CB%99%E2%80%93%E2%BF%BB%E3%80%87%E3%90%80%E3%90%81%E4%B6%B4%E4%B6%B5U1%5B%EE%80%A5%EE%80%A6%EE%80%A7%EE%80%B8%EE%80%B9%5DU2%5B%EE%89%9A%EE%89%9B%EE%89%AC%EE%89%AD%5DU3%5B%EE%93%BE%EE%93%BF%EE%94%80%EE%94%8B%EE%94%8C%5D.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapPercentEncoded.js.map b/tests/baselines/reference/sourceMapPercentEncoded.js.map new file mode 100644 index 00000000000..8c5d347cde9 --- /dev/null +++ b/tests/baselines/reference/sourceMapPercentEncoded.js.map @@ -0,0 +1,3 @@ +//// [①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].js.map] +{"version":3,"file":"①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].js","sourceRoot":"","sources":["①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,CAAC,CAAC;AACV,IAAI,CAAC,GAAG,CAAC,CAAC;AACV,IAAI,CAAC,GAAG,CAAC,CAAC"} +//// https://sokra.github.io/source-map-visualization#base64,dmFyIGEgPSAxOw0KdmFyIGIgPSAyOw0KdmFyIGMgPSAzOw0KLy8jIHNvdXJjZU1hcHBpbmdVUkw9JUUyJTkxJUEwJUUyJTg1JUFCJUUzJTg0JUE4JUUzJTg0JUE5JTIwJUU1JTk1JThBJUU5JTk4JUJGJUU5JUJDJUJFJUU5JUJEJTg0JUU0JUI4JTgyJUU0JUI4JTg0JUU3JThCJTlBJUU3JThCJTlCJUU3JThCJTlDJUU3JThCJTlEJUVGJUE4JUE4JUVGJUE4JUE5JUNCJThBJUNCJThCJUNCJTk5JUUyJTgwJTkzJUUyJUJGJUJCJUUzJTgwJTg3JUUzJTkwJTgwJUUzJTkwJTgxJUU0JUI2JUI0JUU0JUI2JUI1VTElNUIlRUUlODAlQTUlRUUlODAlQTYlRUUlODAlQTclRUUlODAlQjglRUUlODAlQjklNURVMiU1QiVFRSU4OSU5QSVFRSU4OSU5QiVFRSU4OSVBQyVFRSU4OSVBRCU1RFUzJTVCJUVFJTkzJUJFJUVFJTkzJUJGJUVFJTk0JTgwJUVFJTk0JThCJUVFJTk0JThDJTVELmpzLm1hcA==,eyJ2ZXJzaW9uIjozLCJmaWxlIjoi4pGg4oWr44So44SpIOWViumYv+m8vum9hOS4guS4hOeLmueLm+eLnOeLne+oqO+oqcuKy4vLmeKAk+K/u+OAh+OQgOOQgeS2tOS2tVUxW+6Ape6Apu6Ap+6AuO6AuV1VMlvuiZruiZvuiazuia1dVTNb7pO+7pO/7pSA7pSL7pSMXS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIuKRoOKFq+OEqOOEqSDllYrpmL/pvL7pvYTkuILkuITni5rni5vni5zni53vqKjvqKnLisuLy5nigJPiv7vjgIfjkIDjkIHktrTktrVVMVvugKXugKbugKfugLjugLldVTJb7oma7omb7oms7omtXVUzW+6Tvu6Tv+6UgO6Ui+6UjF0udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFDO0FBQ1YsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFDO0FBQ1YsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFDIn0=,dmFyIGEgPSAxOwp2YXIgYiA9IDI7CnZhciBjID0gMzs= diff --git a/tests/baselines/reference/sourceMapPercentEncoded.sourcemap.txt b/tests/baselines/reference/sourceMapPercentEncoded.sourcemap.txt new file mode 100644 index 00000000000..3a62f36d898 --- /dev/null +++ b/tests/baselines/reference/sourceMapPercentEncoded.sourcemap.txt @@ -0,0 +1,76 @@ +=================================================================== +JsFile: ①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].js +mapUrl: %E2%91%A0%E2%85%AB%E3%84%A8%E3%84%A9%20%E5%95%8A%E9%98%BF%E9%BC%BE%E9%BD%84%E4%B8%82%E4%B8%84%E7%8B%9A%E7%8B%9B%E7%8B%9C%E7%8B%9D%EF%A8%A8%EF%A8%A9%CB%8A%CB%8B%CB%99%E2%80%93%E2%BF%BB%E3%80%87%E3%90%80%E3%90%81%E4%B6%B4%E4%B6%B5U1%5B%EE%80%A5%EE%80%A6%EE%80%A7%EE%80%B8%EE%80%B9%5DU2%5B%EE%89%9A%EE%89%9B%EE%89%AC%EE%89%AD%5DU3%5B%EE%93%BE%EE%93%BF%EE%94%80%EE%94%8B%EE%94%8C%5D.js.map +sourceRoot: +sources: ①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].js +sourceFile:①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].ts +------------------------------------------------------------------- +>>>var a = 1; +1 > +2 >^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^-> +1 > +2 >var +3 > a +4 > = +5 > 1 +6 > ; +1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) +2 >Emitted(1, 5) Source(1, 5) + SourceIndex(0) +3 >Emitted(1, 6) Source(1, 6) + SourceIndex(0) +4 >Emitted(1, 9) Source(1, 9) + SourceIndex(0) +5 >Emitted(1, 10) Source(1, 10) + SourceIndex(0) +6 >Emitted(1, 11) Source(1, 11) + SourceIndex(0) +--- +>>>var b = 2; +1-> +2 >^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^-> +1-> + > +2 >var +3 > b +4 > = +5 > 2 +6 > ; +1->Emitted(2, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(2, 5) Source(2, 5) + SourceIndex(0) +3 >Emitted(2, 6) Source(2, 6) + SourceIndex(0) +4 >Emitted(2, 9) Source(2, 9) + SourceIndex(0) +5 >Emitted(2, 10) Source(2, 10) + SourceIndex(0) +6 >Emitted(2, 11) Source(2, 11) + SourceIndex(0) +--- +>>>var c = 3; +1-> +2 >^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> + > +2 >var +3 > c +4 > = +5 > 3 +6 > ; +1->Emitted(3, 1) Source(3, 1) + SourceIndex(0) +2 >Emitted(3, 5) Source(3, 5) + SourceIndex(0) +3 >Emitted(3, 6) Source(3, 6) + SourceIndex(0) +4 >Emitted(3, 9) Source(3, 9) + SourceIndex(0) +5 >Emitted(3, 10) Source(3, 10) + SourceIndex(0) +6 >Emitted(3, 11) Source(3, 11) + SourceIndex(0) +--- +>>>//# sourceMappingURL=%E2%91%A0%E2%85%AB%E3%84%A8%E3%84%A9%20%E5%95%8A%E9%98%BF%E9%BC%BE%E9%BD%84%E4%B8%82%E4%B8%84%E7%8B%9A%E7%8B%9B%E7%8B%9C%E7%8B%9D%EF%A8%A8%EF%A8%A9%CB%8A%CB%8B%CB%99%E2%80%93%E2%BF%BB%E3%80%87%E3%90%80%E3%90%81%E4%B6%B4%E4%B6%B5U1%5B%EE%80%A5%EE%80%A6%EE%80%A7%EE%80%B8%EE%80%B9%5DU2%5B%EE%89%9A%EE%89%9B%EE%89%AC%EE%89%AD%5DU3%5B%EE%93%BE%EE%93%BF%EE%94%80%EE%94%8B%EE%94%8C%5D.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapPercentEncoded.symbols b/tests/baselines/reference/sourceMapPercentEncoded.symbols new file mode 100644 index 00000000000..6e302dda5ba --- /dev/null +++ b/tests/baselines/reference/sourceMapPercentEncoded.symbols @@ -0,0 +1,10 @@ +=== tests/cases/compiler/①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].ts === +var a = 1; +>a : Symbol(a, Decl(①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].ts, 0, 3)) + +var b = 2; +>b : Symbol(b, Decl(①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].ts, 1, 3)) + +var c = 3; +>c : Symbol(c, Decl(①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].ts, 2, 3)) + diff --git a/tests/baselines/reference/sourceMapPercentEncoded.types b/tests/baselines/reference/sourceMapPercentEncoded.types new file mode 100644 index 00000000000..9683b257e96 --- /dev/null +++ b/tests/baselines/reference/sourceMapPercentEncoded.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].ts === +var a = 1; +>a : number +>1 : 1 + +var b = 2; +>b : number +>2 : 2 + +var c = 3; +>c : number +>3 : 3 + diff --git a/tests/cases/compiler/sourceMapPercentEncoded.ts b/tests/cases/compiler/sourceMapPercentEncoded.ts new file mode 100644 index 00000000000..ca0316fdcfc --- /dev/null +++ b/tests/cases/compiler/sourceMapPercentEncoded.ts @@ -0,0 +1,6 @@ +// @sourceMap: true + +// @Filename: ①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].ts +var a = 1; +var b = 2; +var c = 3; \ No newline at end of file