Repository navigation
Decode JavaScript Unicode code point escapes during extraction - #1394
theman6660 wants to merge 1 commit into
Conversation
| codepoint = codepoint_escape_re.match(string, escape_pos + 2) | ||
| if codepoint is not None: | ||
| value = int(codepoint.group(1), 16) | ||
| if value <= 0x10ffff: |
There was a problem hiding this comment.
Why is this check needed?
EDIT: ah, right, that's basically the maximum for JavaScript. Sure, doesn't hurt here...
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1394 +/- ##
==========================================
+ Coverage 93.37% 93.44% +0.07%
==========================================
Files 27 27
Lines 4922 4931 +9
==========================================
+ Hits 4596 4608 +12
+ Misses 326 323 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟢 Approval recommended
The focused implementation preserves existing fallback behavior and has targeted regression coverage, with no blocking issues identified in static review.
No open issues 🎉
What changed in this PR
This PR aligns JavaScript message extraction with runtime string values by decoding lowercase \u{...} Unicode code point escapes.
Changes:
- Decode valid braced escapes, including supplementary code points and leading zeros, while preserving legacy handling and malformed-input fallback.
- Add 29 regression cases covering quoted strings, templates, extraction results, line numbers, and escape edge cases.
| File | Description |
|---|---|
| tests/messages/test_js_unicode_codepoints.py | Adds decoding and public extraction API regression coverage. |
| babel/messages/jslexer.py | Recognizes and decodes valid braced Unicode code point escapes. |
Review effort: Balanced
JavaScript gettext("Hello \u{1F600}") evaluates to "Hello 😀", but extraction currently produces the literal text "Hello u{1F600}". The resulting translation key does not match the runtime message.
Recognize lowercase-u braced hexadecimal escapes in unquote_string(), including supplementary code points and leading zeros. Preserve the existing fallback for malformed or out-of-range escapes and leave legacy hexadecimal/Unicode handling intact.
Add 29 cases across single/double quotes and template strings, including the public JavaScript extraction API, line numbers, NUL, BMP and maximum code points, adjacent/legacy escapes and malformed inputs. Before the fix, 23 failed and 6 passed. All 29 now pass; the focused lexer/extractor set has 49 passing tests. A separate Node.js runtime check agrees on 30 valid literal values. Full Babel suite with imported CLDR 48.2: 7860 passed, 7 skipped, 2 xfailed (one existing pytest deprecation warning). Project pre-commit hooks and git diff --check pass.
Prepared with OpenAI Codex assistance. No production usage, human review or upstream CI is claimed.