Skip to content

fix: escape single quotes and backslashes in IR string output#90

Open
AugustHagedal wants to merge 1 commit intoSnapchat:mainfrom
AugustHagedal:fix/ir-string-escaping
Open

fix: escape single quotes and backslashes in IR string output#90
AugustHagedal wants to merge 1 commit intoSnapchat:mainfrom
AugustHagedal:fix/ir-string-escaping

Conversation

@AugustHagedal
Copy link

Summary

  • Strings containing ' or \ in their value broke the IR parser because appendQuotedString emitted them unescaped inside single-quote delimiters (a TODO comment had flagged this since the file was written)
  • The LiteralString IR case had its own inline template that bypassed appendQuotedString entirely, so it also emitted unescaped strings

Changes

  • Add escapeIRString() helper in IRtoString.ts that escapes \, ', \n, \r, and \t
  • Apply it in appendQuotedString(), removing the long-standing TODO(simon): Escape quotes comment
  • Fix the LiteralString case to route through appendQuotedString instead of its own inline template literal
  • Add two regression tests: single quote and backslash in string literals (120 tests, all passing)

Test plan

  • Run existing test suite — all 118 tests continue to pass
  • New test: escapes single quotes in string literals — verifies storestring 'it\'s a test'
  • New test: escapes backslashes in string literals — verifies storestring 'C:\\Users\\file'
Tests: 120 passed, 120 total

🤖 Generated with Claude Code

Strings containing single quotes or backslashes would break the IR
parser because appendQuotedString emitted them unescaped inside
single-quote delimiters.

- Add escapeIRString() helper that escapes \, ', \n, \r, \t
- Apply it in appendQuotedString() (removes the long-standing TODO)
- Fix the LiteralString IR case to route through appendQuotedString
  instead of its own inline template literal
- Add two regression tests (single-quote and backslash in string literals)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant