Merge pull request #2143 from Microsoft/escapingTheTemplateOfDoomAgain

Fix character escaping for downlevel template strings
This commit is contained in:
Daniel Rosenwasser 2015-02-25 18:41:15 -08:00
commit 0162330d50
49 changed files with 287 additions and 2 deletions

View file

@ -607,7 +607,7 @@ module ts {
}
var backslashOrDoubleQuote = /[\"\\]/g;
var escapedCharsRegExp = /[\0-\19\t\v\f\b\0\r\n\u2028\u2029\u0085]/g;
var escapedCharsRegExp = /[\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
var escapedCharsMap: Map<string> = {
"\0": "\\0",
"\t": "\\t",
@ -624,7 +624,7 @@ module ts {
};
/**
* Based heavily on the abstract 'Quote' operation from ECMA-262 (24.3.2.2),
* Based heavily on the abstract 'Quote'/ 'QuoteJSONString' operation from ECMA-262 (24.3.2.2),
* but augmented for a few select characters.
* Note that this doesn't actually wrap the input in double quotes.
*/

View file

@ -0,0 +1,13 @@
tests/cases/conformance/es6/templates/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.ts(7,3): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher.
==== tests/cases/conformance/es6/templates/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.ts (1 errors) ====
function f(...x: any[]) {
}
f `0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher.

View file

@ -0,0 +1,17 @@
//// [taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.ts]
function f(...x: any[]) {
}
f `0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n`
//// [taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01.js]
function f() {
var x = [];
for (var _i = 0; _i < arguments.length; _i++) {
x[_i - 0] = arguments[_i];
}
}
f "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n";

View file

@ -0,0 +1,12 @@
//// [taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01_ES6.ts]
function f(...x: any[]) {
}
f `0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n`
//// [taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01_ES6.js]
function f(...x) {
}
f `0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n`;

View file

@ -0,0 +1,11 @@
=== tests/cases/conformance/es6/templates/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes01_ES6.ts ===
function f(...x: any[]) {
>f : (...x: any[]) => void
>x : any[]
}
f `0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n`
>f : (...x: any[]) => void

View file

@ -0,0 +1,7 @@
//// [taggedTemplateStringsPlainCharactersThatArePartsOfEscapes02.ts]
`0${ " " }1${ " " }2${ " " }3${ " " }4${ " " }5${ " " }6${ " " }7${ " " }8${ " " }9${ " " }10${ " " }11${ " " }12${ " " }13${ " " }14${ " " }15${ " " }16${ " " }17${ " " }18${ " " }19${ " " }20${ " " }2028${ " " }2029${ " " }0085${ " " }t${ " " }v${ " " }f${ " " }b${ " " }r${ " " }n`
//// [taggedTemplateStringsPlainCharactersThatArePartsOfEscapes02.js]
"0" + " " + "1" + " " + "2" + " " + "3" + " " + "4" + " " + "5" + " " + "6" + " " + "7" + " " + "8" + " " + "9" + " " + "10" + " " + "11" + " " + "12" + " " + "13" + " " + "14" + " " + "15" + " " + "16" + " " + "17" + " " + "18" + " " + "19" + " " + "20" + " " + "2028" + " " + "2029" + " " + "0085" + " " + "t" + " " + "v" + " " + "f" + " " + "b" + " " + "r" + " " + "n";

View file

@ -0,0 +1,5 @@
=== tests/cases/conformance/es6/templates/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes02.ts ===
No type information for this code.
No type information for this code.`0${ " " }1${ " " }2${ " " }3${ " " }4${ " " }5${ " " }6${ " " }7${ " " }8${ " " }9${ " " }10${ " " }11${ " " }12${ " " }13${ " " }14${ " " }15${ " " }16${ " " }17${ " " }18${ " " }19${ " " }20${ " " }2028${ " " }2029${ " " }0085${ " " }t${ " " }v${ " " }f${ " " }b${ " " }r${ " " }n`
No type information for this code.

View file

@ -0,0 +1,12 @@
//// [taggedTemplateStringsPlainCharactersThatArePartsOfEscapes02_ES6.ts]
function f(...x: any[]) {
}
f `0${ " " }1${ " " }2${ " " }3${ " " }4${ " " }5${ " " }6${ " " }7${ " " }8${ " " }9${ " " }10${ " " }11${ " " }12${ " " }13${ " " }14${ " " }15${ " " }16${ " " }17${ " " }18${ " " }19${ " " }20${ " " }2028${ " " }2029${ " " }0085${ " " }t${ " " }v${ " " }f${ " " }b${ " " }r${ " " }n`
//// [taggedTemplateStringsPlainCharactersThatArePartsOfEscapes02_ES6.js]
function f(...x) {
}
f `0${" "}1${" "}2${" "}3${" "}4${" "}5${" "}6${" "}7${" "}8${" "}9${" "}10${" "}11${" "}12${" "}13${" "}14${" "}15${" "}16${" "}17${" "}18${" "}19${" "}20${" "}2028${" "}2029${" "}0085${" "}t${" "}v${" "}f${" "}b${" "}r${" "}n`;

View file

@ -0,0 +1,11 @@
=== tests/cases/conformance/es6/templates/taggedTemplateStringsPlainCharactersThatArePartsOfEscapes02_ES6.ts ===
function f(...x: any[]) {
>f : (...x: any[]) => void
>x : any[]
}
f `0${ " " }1${ " " }2${ " " }3${ " " }4${ " " }5${ " " }6${ " " }7${ " " }8${ " " }9${ " " }10${ " " }11${ " " }12${ " " }13${ " " }14${ " " }15${ " " }16${ " " }17${ " " }18${ " " }19${ " " }20${ " " }2028${ " " }2029${ " " }0085${ " " }t${ " " }v${ " " }f${ " " }b${ " " }r${ " " }n`
>f : (...x: any[]) => void

View file

@ -0,0 +1,7 @@
//// [templateStringControlCharacterEscapes01.ts]
var x = `\0\x00\u0000 0 00 0000`;
//// [templateStringControlCharacterEscapes01.js]
var x = "\0\0\0 0 00 0000";

View file

@ -0,0 +1,6 @@
=== tests/cases/conformance/es6/templates/templateStringControlCharacterEscapes01.ts ===
var x = `\0\x00\u0000 0 00 0000`;
>x : string

View file

@ -0,0 +1,6 @@
//// [templateStringControlCharacterEscapes01_ES6.ts]
var x = `\0\x00\u0000 0 00 0000`;
//// [templateStringControlCharacterEscapes01_ES6.js]
var x = `\0\x00\u0000 0 00 0000`;

View file

@ -0,0 +1,5 @@
=== tests/cases/conformance/es6/templates/templateStringControlCharacterEscapes01_ES6.ts ===
var x = `\0\x00\u0000 0 00 0000`;
>x : string

View file

@ -0,0 +1,7 @@
//// [templateStringControlCharacterEscapes02.ts]
var x = `\x19\u0019 19`;
//// [templateStringControlCharacterEscapes02.js]
var x = "\u0019\u0019 19";

View file

@ -0,0 +1,6 @@
=== tests/cases/conformance/es6/templates/templateStringControlCharacterEscapes02.ts ===
var x = `\x19\u0019 19`;
>x : string

View file

@ -0,0 +1,6 @@
//// [templateStringControlCharacterEscapes02_ES6.ts]
var x = `\x19\u0019 19`;
//// [templateStringControlCharacterEscapes02_ES6.js]
var x = `\x19\u0019 19`;

View file

@ -0,0 +1,5 @@
=== tests/cases/conformance/es6/templates/templateStringControlCharacterEscapes02_ES6.ts ===
var x = `\x19\u0019 19`;
>x : string

View file

@ -0,0 +1,7 @@
//// [templateStringControlCharacterEscapes03.ts]
var x = `\x1F\u001f 1F 1f`;
//// [templateStringControlCharacterEscapes03.js]
var x = "\u001f\u001f 1F 1f";

View file

@ -0,0 +1,6 @@
=== tests/cases/conformance/es6/templates/templateStringControlCharacterEscapes03.ts ===
var x = `\x1F\u001f 1F 1f`;
>x : string

View file

@ -0,0 +1,6 @@
//// [templateStringControlCharacterEscapes03_ES6.ts]
var x = `\x1F\u001f 1F 1f`;
//// [templateStringControlCharacterEscapes03_ES6.js]
var x = `\x1F\u001f 1F 1f`;

View file

@ -0,0 +1,5 @@
=== tests/cases/conformance/es6/templates/templateStringControlCharacterEscapes03_ES6.ts ===
var x = `\x1F\u001f 1F 1f`;
>x : string

View file

@ -0,0 +1,7 @@
//// [templateStringControlCharacterEscapes04.ts]
var x = `\x20\u0020 20`;
//// [templateStringControlCharacterEscapes04.js]
var x = " 20";

View file

@ -0,0 +1,6 @@
=== tests/cases/conformance/es6/templates/templateStringControlCharacterEscapes04.ts ===
var x = `\x20\u0020 20`;
>x : string

View file

@ -0,0 +1,6 @@
//// [templateStringControlCharacterEscapes04_ES6.ts]
var x = `\x20\u0020 20`;
//// [templateStringControlCharacterEscapes04_ES6.js]
var x = `\x20\u0020 20`;

View file

@ -0,0 +1,5 @@
=== tests/cases/conformance/es6/templates/templateStringControlCharacterEscapes04_ES6.ts ===
var x = `\x20\u0020 20`;
>x : string

View file

@ -0,0 +1,6 @@
//// [templateStringPlainCharactersThatArePartsOfEscapes01.ts]
`0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n`
//// [templateStringPlainCharactersThatArePartsOfEscapes01.js]
"0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n";

View file

@ -0,0 +1,4 @@
=== tests/cases/conformance/es6/templates/templateStringPlainCharactersThatArePartsOfEscapes01.ts ===
No type information for this code.`0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n`
No type information for this code.

View file

@ -0,0 +1,6 @@
//// [templateStringPlainCharactersThatArePartsOfEscapes01_ES6.ts]
`0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n`
//// [templateStringPlainCharactersThatArePartsOfEscapes01_ES6.js]
`0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n`;

View file

@ -0,0 +1,4 @@
=== tests/cases/conformance/es6/templates/templateStringPlainCharactersThatArePartsOfEscapes01_ES6.ts ===
No type information for this code.`0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n`
No type information for this code.

View file

@ -0,0 +1,7 @@
//// [templateStringPlainCharactersThatArePartsOfEscapes02.ts]
`0${ " " }1${ " " }2${ " " }3${ " " }4${ " " }5${ " " }6${ " " }7${ " " }8${ " " }9${ " " }10${ " " }11${ " " }12${ " " }13${ " " }14${ " " }15${ " " }16${ " " }17${ " " }18${ " " }19${ " " }20${ " " }2028${ " " }2029${ " " }0085${ " " }t${ " " }v${ " " }f${ " " }b${ " " }r${ " " }n`
//// [templateStringPlainCharactersThatArePartsOfEscapes02.js]
"0" + " " + "1" + " " + "2" + " " + "3" + " " + "4" + " " + "5" + " " + "6" + " " + "7" + " " + "8" + " " + "9" + " " + "10" + " " + "11" + " " + "12" + " " + "13" + " " + "14" + " " + "15" + " " + "16" + " " + "17" + " " + "18" + " " + "19" + " " + "20" + " " + "2028" + " " + "2029" + " " + "0085" + " " + "t" + " " + "v" + " " + "f" + " " + "b" + " " + "r" + " " + "n";

View file

@ -0,0 +1,5 @@
=== tests/cases/conformance/es6/templates/templateStringPlainCharactersThatArePartsOfEscapes02.ts ===
No type information for this code.
No type information for this code.`0${ " " }1${ " " }2${ " " }3${ " " }4${ " " }5${ " " }6${ " " }7${ " " }8${ " " }9${ " " }10${ " " }11${ " " }12${ " " }13${ " " }14${ " " }15${ " " }16${ " " }17${ " " }18${ " " }19${ " " }20${ " " }2028${ " " }2029${ " " }0085${ " " }t${ " " }v${ " " }f${ " " }b${ " " }r${ " " }n`
No type information for this code.

View file

@ -0,0 +1,6 @@
//// [templateStringPlainCharactersThatArePartsOfEscapes02_ES6.ts]
`0${ " " }1${ " " }2${ " " }3${ " " }4${ " " }5${ " " }6${ " " }7${ " " }8${ " " }9${ " " }10${ " " }11${ " " }12${ " " }13${ " " }14${ " " }15${ " " }16${ " " }17${ " " }18${ " " }19${ " " }20${ " " }2028${ " " }2029${ " " }0085${ " " }t${ " " }v${ " " }f${ " " }b${ " " }r${ " " }n`
//// [templateStringPlainCharactersThatArePartsOfEscapes02_ES6.js]
`0${" "}1${" "}2${" "}3${" "}4${" "}5${" "}6${" "}7${" "}8${" "}9${" "}10${" "}11${" "}12${" "}13${" "}14${" "}15${" "}16${" "}17${" "}18${" "}19${" "}20${" "}2028${" "}2029${" "}0085${" "}t${" "}v${" "}f${" "}b${" "}r${" "}n`;

View file

@ -0,0 +1,4 @@
=== tests/cases/conformance/es6/templates/templateStringPlainCharactersThatArePartsOfEscapes02_ES6.ts ===
No type information for this code.`0${ " " }1${ " " }2${ " " }3${ " " }4${ " " }5${ " " }6${ " " }7${ " " }8${ " " }9${ " " }10${ " " }11${ " " }12${ " " }13${ " " }14${ " " }15${ " " }16${ " " }17${ " " }18${ " " }19${ " " }20${ " " }2028${ " " }2029${ " " }0085${ " " }t${ " " }v${ " " }f${ " " }b${ " " }r${ " " }n`
No type information for this code.

View file

@ -0,0 +1,7 @@

function f(...x: any[]) {
}
f `0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n`

View file

@ -0,0 +1,7 @@
// @target: es6
function f(...x: any[]) {
}
f `0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n`

View file

@ -0,0 +1,3 @@

`0${ " " }1${ " " }2${ " " }3${ " " }4${ " " }5${ " " }6${ " " }7${ " " }8${ " " }9${ " " }10${ " " }11${ " " }12${ " " }13${ " " }14${ " " }15${ " " }16${ " " }17${ " " }18${ " " }19${ " " }20${ " " }2028${ " " }2029${ " " }0085${ " " }t${ " " }v${ " " }f${ " " }b${ " " }r${ " " }n`

View file

@ -0,0 +1,7 @@
// @target: es6
function f(...x: any[]) {
}
f `0${ " " }1${ " " }2${ " " }3${ " " }4${ " " }5${ " " }6${ " " }7${ " " }8${ " " }9${ " " }10${ " " }11${ " " }12${ " " }13${ " " }14${ " " }15${ " " }16${ " " }17${ " " }18${ " " }19${ " " }20${ " " }2028${ " " }2029${ " " }0085${ " " }t${ " " }v${ " " }f${ " " }b${ " " }r${ " " }n`

View file

@ -0,0 +1,3 @@

var x = `\0\x00\u0000 0 00 0000`;

View file

@ -0,0 +1,3 @@
// @target: es6
var x = `\0\x00\u0000 0 00 0000`;

View file

@ -0,0 +1,3 @@

var x = `\x19\u0019 19`;

View file

@ -0,0 +1,3 @@
// @target: es6
var x = `\x19\u0019 19`;

View file

@ -0,0 +1,3 @@

var x = `\x1F\u001f 1F 1f`;

View file

@ -0,0 +1,3 @@
// @target: es6
var x = `\x1F\u001f 1F 1f`;

View file

@ -0,0 +1,3 @@

var x = `\x20\u0020 20`;

View file

@ -0,0 +1,3 @@
// @target: es6
var x = `\x20\u0020 20`;

View file

@ -0,0 +1,2 @@

`0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n`

View file

@ -0,0 +1,3 @@
// @target: es6
`0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2028 2029 0085 t v f b r n`

View file

@ -0,0 +1,3 @@

`0${ " " }1${ " " }2${ " " }3${ " " }4${ " " }5${ " " }6${ " " }7${ " " }8${ " " }9${ " " }10${ " " }11${ " " }12${ " " }13${ " " }14${ " " }15${ " " }16${ " " }17${ " " }18${ " " }19${ " " }20${ " " }2028${ " " }2029${ " " }0085${ " " }t${ " " }v${ " " }f${ " " }b${ " " }r${ " " }n`

View file

@ -0,0 +1,3 @@
// @target: es6
`0${ " " }1${ " " }2${ " " }3${ " " }4${ " " }5${ " " }6${ " " }7${ " " }8${ " " }9${ " " }10${ " " }11${ " " }12${ " " }13${ " " }14${ " " }15${ " " }16${ " " }17${ " " }18${ " " }19${ " " }20${ " " }2028${ " " }2029${ " " }0085${ " " }t${ " " }v${ " " }f${ " " }b${ " " }r${ " " }n`