Repository navigation
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The one-line mapping addition correctly completes the ECMAScript escape table and is fully covered by focused, correct regression tests.
No open issues 🎉
What changed in this PR
Babel's JavaScript string decoder (unquote_string) omitted the v (vertical tab, U+000B) single-character escape from its escapes lookup table, causing \v to be decoded as a bare v. This meant extracted messages (e.g. via gettext('before\vafter')) diverged from the actual runtime string. The PR adds the missing mapping, which is referenced by ECMAScript Table 33, and covers it with regression tests across single quotes, double quotes, and template strings.
Changes:
- Add
'v': '\v'to theescapesdict inbabel/messages/jslexer.py. - Add lexer-level tests for leading/interior/trailing
\vacross all three delimiters, plus a test confirming a literal backslash-plus-v(\\v) is left unchanged. - Add an extractor-level test verifying
gettextextraction produces U+000B for all three delimiters.
| File | Description |
|---|---|
| babel/messages/jslexer.py | Adds the missing v → U+000B entry to the escapes table used by unquote_string. |
| tests/messages/test_jslexer.py | Adds parametrized tests for decoding \v and preserving literal \\v; adds the required pytest import. |
| tests/messages/test_js_extract.py | Adds a parametrized extractor test confirming \v decodes to U+000B across delimiters. |
I verified that escapes is the single lookup table consumed in unquote_string (jslexer.py:121-122), so this one change fully covers all three string/template delimiters. The literal-escape test (\\v → \v) correctly exercises the "bogus escape" branch, and pytest is already imported in test_js_extract.py. No issues found.
Review effort: Balanced
Babel's JavaScript string decoder omits
vfrom its simple escape table. As a result,gettext('before\vafter')extracts the messagebeforevafter, which differs from the runtime string containing U+000B. The same defect affects single quotes, double quotes and template strings. ECMAScript defines this escape in Table 33.Add the missing mapping and regression tests for leading, interior and trailing vertical tabs across all three delimiters, plus extractor-level cases. Literal backslash-plus-v sequences remain unchanged.
Validation on Windows, CPython 3.13.14:
git diff --checkpasses. No unrelated formatting changes were made.The full run emits one existing pytest parameterization deprecation warning.
Found by source inspection and prepared with OpenAI Codex assistance. No production incident or human manual review is claimed.