Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Use single replacer for string escaping#22335

Merged
weswigham merged 1 commit into
microsoft:mastermicrosoft/TypeScript:masterfrom
weswigham:robust-string-escapeweswigham/TypeScript:robust-string-escapeCopy head branch name to clipboard
Mar 8, 2018
Merged

Use single replacer for string escaping#22335
weswigham merged 1 commit into
microsoft:mastermicrosoft/TypeScript:masterfrom
weswigham:robust-string-escapeweswigham/TypeScript:robust-string-escapeCopy head branch name to clipboard

Conversation

@weswigham

Copy link
Copy Markdown
Member

The two-stage replacement was making non-null characters look like null chracters to the second replacer, which is no good. Now all the replacing is handled within one replacer, which also does the lookahead for potential octalyness conflicts.

Fixes #21828

Comment thread src/compiler/utilities.ts
function getReplacement(c: string, offset: number, input: string) {
if (c.charCodeAt(0) === CharacterCodes.nullCharacter) {
const lookAhead = input.charCodeAt(offset + c.length);
if (lookAhead >= CharacterCodes._0 && lookAhead <= CharacterCodes._9) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This technically only needs to be 0 through 7 (isOctalDigit), but I'm fine with this.

@DanielRosenwasser

DanielRosenwasser commented Mar 6, 2018

Copy link
Copy Markdown
Member

By the way, I wrote this code back when we couldn't use JSON.stringify, so a decent amount of logic here could probably be replaced with the JSON.stringify + the special cases I mentioned above + str.slice(1, -1).

But that can be another PR.

@weswigham weswigham merged commit 45eaf42 into microsoft:master Mar 8, 2018
@weswigham weswigham deleted the robust-string-escape branch March 8, 2018 01:36
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.