Skip to content

Escape keys in compiled getter via JSON.stringify - #3

Merged
amitport merged 1 commit into
CardForest:masterfrom
CXu0630:fix-compiled-getter-escaping
Nov 20, 2026
Merged

amitport merged 1 commit into
CardForest:masterfrom
CXu0630:fix-compiled-getter-escaping

Conversation

@CXu0630

@CXu0630 CXu0630 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

compiledGetValueFromFn builds the getter as a source string and compiles it with new Function, but it only escaped " in non-identifier keys. As a result:

  • A key containing a backslash returns the wrong value: a\b reads as a + backspace + nothing, so you get undefined.
  • A key containing a line break throws a SyntaxError.
  • A key with a backslash right before a " can close the generated string literal early.

Keys are now written into that source with JSON.stringify(key).

Added cases for the keys above, plus a check that compiled lookups match obj[key].

@amitport amitport left a comment

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.

Thanks @CXu0630 for identifying and fixing compiled-getter escaping and adding regression tests. Reviewed and verified: all 12 tests and the TypeScript build pass, plus additional special-character and intermediate-key checks. This also fixes incorrect lookups for numeric-looking string keys.

@amitport
amitport merged commit 422b677 into CardForest:master Nov 20, 2026
amitport added a commit that referenced this pull request Nov 20, 2026
Publish the CommonJS build and TypeScript declarations, validate before publishing, and credit CXu0630 for PR #3.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.

2 participants