-
Notifications
You must be signed in to change notification settings - Fork 645
[WIP] Port TypeScript PR #60303: Fix template string escaping #1142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@copilot try again |
Co-authored-by: andrewbranch <3277153+andrewbranch@users.noreply.github.com>
Co-authored-by: andrewbranch <3277153+andrewbranch@users.noreply.github.com>
I've successfully ported TypeScript PR #60303 to fix template string escaping (commit 1d3732b). The fix ensures LF newline characters in template literals are not escaped, matching the original TypeScript behavior. Added comprehensive tests including one that mirrors the TypeScript test case. All tests pass with no baseline changes needed. |
- Addresses TypeScript PR #60303 by ensuring \u001f is properly escaped - \n was already handled correctly by existing case '\n': logic - Removed separate test file and added comprehensive tests to utilities_test.go - Fixed the minimal issue: \u001f (Unit Separator) was not being escaped due to < vs <= condition Addresses feedback from code review. Co-authored-by: andrewbranch <3277153+andrewbranch@users.noreply.github.com>
… coverage Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
@@ -28,6 +28,7 @@ func TestEmit(t *testing.T) { | |||
{title: "BooleanLiteral#1", input: `true`, output: `true;`}, | |||
{title: "BooleanLiteral#2", input: `false`, output: `false;`}, | |||
{title: "NoSubstitutionTemplateLiteral", input: "``", output: "``;"}, | |||
{title: "NoSubstitutionTemplateLiteral#2", input: "`\n`", output: "`\n`;"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was mistaken; this test passes even without this PR's change. Add a test which would have failed before this PR's fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test case for \u001f
character in template literals that would have failed before this PR's fix. The test demonstrates that \u001f
is now properly escaped to \u001F
while preserving the correct behavior for \n
(which should not be escaped). Commit fadf221.
…rol characters Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
@@ -205,6 +205,21 @@ func canUseOriginalText(node *ast.LiteralLikeNode, flags getLiteralTextFlags) bo | |||
} | |||
} | |||
|
|||
// For template literals, check if they contain characters that need escaping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this code block necessary? Try removing it and see if tests still pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested removing the code block - it causes test TestEmit/NoSubstitutionTemplateLiteral#3
to fail. The code block is necessary because it forces template literals with control characters to go through the escaping path in getLiteralText()
rather than using the original source text. Without it, canUseOriginalText()
returns true and template literals containing \u001f
would not be properly escaped.
Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.
Original issue description:
Fixes #1121.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.