Skip to content

Improper string escaping #21828

Closed
Closed
@clydin

Description

@clydin

TypeScript Version: 2.6+

Search Terms:

Code

const a1 = "\0";
const b1 = "\x01";
const c1 = "\01";
const d1 = "\\0041";

const a2 = `\0`;
const b2 = `\x01`;
const c2 = `\01`;
const d2 = `\\0041`;

Expected behavior:

var a1 = "\0";
var b1 = "\x01"; // this should be consistency with b2
var c1 = "\01";  // this should either remain as is or be "\u0001"
var d1 = "\\0041";
var a2 = "\0";
var b2 = "\u0001";
var c2 = "\01";  // this should either remain "\01" or be "\u0001" (same as c1)
var d2 = "\\0041";  // This should not be altered

Actual behavior:

var a1 = "\0";
var b1 = "\x01";  
var c1 = "\01"; 
var d1 = "\\0041";
var a2 = "\0";
var b2 = "\u0001";
var c2 = "\x001";
var d2 = "\\x00041";   // This is broken and the main concern

The behavior demonstrated in variable d2 is the primary concern as the output has been transformed into a completely different value.

Playground Link:
Example

Related Issues:

Traced the change to this PR: #18026

angular/angular-cli#9567

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions