Skip to content

Commit 1f852ed

Browse files
authored
Percent-encode source map URLs (microsoft#41102)
1 parent 1074fd4 commit 1f852ed

File tree

7 files changed

+127
-8
lines changed

7 files changed

+127
-8
lines changed

src/compiler/emitter.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -606,18 +606,19 @@ namespace ts {
606606
if (getRootLength(sourceMapDir) === 0) {
607607
// The relative paths are relative to the common directory
608608
sourceMapDir = combinePaths(host.getCommonSourceDirectory(), sourceMapDir);
609-
return getRelativePathToDirectoryOrUrl(
610-
getDirectoryPath(normalizePath(filePath)), // get the relative sourceMapDir path based on jsFilePath
611-
combinePaths(sourceMapDir, sourceMapFile), // this is where user expects to see sourceMap
612-
host.getCurrentDirectory(),
613-
host.getCanonicalFileName,
614-
/*isAbsolutePathAnUrl*/ true);
609+
return encodeURI(
610+
getRelativePathToDirectoryOrUrl(
611+
getDirectoryPath(normalizePath(filePath)), // get the relative sourceMapDir path based on jsFilePath
612+
combinePaths(sourceMapDir, sourceMapFile), // this is where user expects to see sourceMap
613+
host.getCurrentDirectory(),
614+
host.getCanonicalFileName,
615+
/*isAbsolutePathAnUrl*/ true));
615616
}
616617
else {
617-
return combinePaths(sourceMapDir, sourceMapFile);
618+
return encodeURI(combinePaths(sourceMapDir, sourceMapFile));
618619
}
619620
}
620-
return sourceMapFile;
621+
return encodeURI(sourceMapFile);
621622
}
622623
}
623624

tests/baselines/reference/sourceMapPercentEncoded.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/sourceMapPercentEncoded.js.map

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
===================================================================
2+
JsFile: ①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].js
3+
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
4+
sourceRoot:
5+
sources: ①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].ts
6+
===================================================================
7+
-------------------------------------------------------------------
8+
emittedFile:tests/cases/compiler/①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].js
9+
sourceFile:①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].ts
10+
-------------------------------------------------------------------
11+
>>>var a = 1;
12+
1 >
13+
2 >^^^^
14+
3 > ^
15+
4 > ^^^
16+
5 > ^
17+
6 > ^
18+
7 > ^->
19+
1 >
20+
2 >var
21+
3 > a
22+
4 > =
23+
5 > 1
24+
6 > ;
25+
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
26+
2 >Emitted(1, 5) Source(1, 5) + SourceIndex(0)
27+
3 >Emitted(1, 6) Source(1, 6) + SourceIndex(0)
28+
4 >Emitted(1, 9) Source(1, 9) + SourceIndex(0)
29+
5 >Emitted(1, 10) Source(1, 10) + SourceIndex(0)
30+
6 >Emitted(1, 11) Source(1, 11) + SourceIndex(0)
31+
---
32+
>>>var b = 2;
33+
1->
34+
2 >^^^^
35+
3 > ^
36+
4 > ^^^
37+
5 > ^
38+
6 > ^
39+
7 > ^->
40+
1->
41+
>
42+
2 >var
43+
3 > b
44+
4 > =
45+
5 > 2
46+
6 > ;
47+
1->Emitted(2, 1) Source(2, 1) + SourceIndex(0)
48+
2 >Emitted(2, 5) Source(2, 5) + SourceIndex(0)
49+
3 >Emitted(2, 6) Source(2, 6) + SourceIndex(0)
50+
4 >Emitted(2, 9) Source(2, 9) + SourceIndex(0)
51+
5 >Emitted(2, 10) Source(2, 10) + SourceIndex(0)
52+
6 >Emitted(2, 11) Source(2, 11) + SourceIndex(0)
53+
---
54+
>>>var c = 3;
55+
1->
56+
2 >^^^^
57+
3 > ^
58+
4 > ^^^
59+
5 > ^
60+
6 > ^
61+
7 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
62+
1->
63+
>
64+
2 >var
65+
3 > c
66+
4 > =
67+
5 > 3
68+
6 > ;
69+
1->Emitted(3, 1) Source(3, 1) + SourceIndex(0)
70+
2 >Emitted(3, 5) Source(3, 5) + SourceIndex(0)
71+
3 >Emitted(3, 6) Source(3, 6) + SourceIndex(0)
72+
4 >Emitted(3, 9) Source(3, 9) + SourceIndex(0)
73+
5 >Emitted(3, 10) Source(3, 10) + SourceIndex(0)
74+
6 >Emitted(3, 11) Source(3, 11) + SourceIndex(0)
75+
---
76+
>>>//# 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
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/compiler/①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].ts ===
2+
var a = 1;
3+
>a : Symbol(a, Decl(①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].ts, 0, 3))
4+
5+
var b = 2;
6+
>b : Symbol(b, Decl(①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].ts, 1, 3))
7+
8+
var c = 3;
9+
>c : Symbol(c, Decl(①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].ts, 2, 3))
10+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].ts ===
2+
var a = 1;
3+
>a : number
4+
>1 : 1
5+
6+
var b = 2;
7+
>b : number
8+
>2 : 2
9+
10+
var c = 3;
11+
>c : number
12+
>3 : 3
13+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @sourceMap: true
2+
3+
// @Filename: ①Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[].ts
4+
var a = 1;
5+
var b = 2;
6+
var c = 3;

0 commit comments

Comments
 (0)