Skip to content

Decode JavaScript vertical-tab escapes during message extraction - #1409

Open
Dcastroro wants to merge 1 commit into
python-babel:masterfrom
Dcastroro:fix/decode-javascript-vertical-tab-escapes
Open

Dcastroro wants to merge 1 commit into
python-babel:masterfrom
Dcastroro:fix/decode-javascript-vertical-tab-escapes

Conversation

@Dcastroro

Copy link
Copy Markdown

Babel's JavaScript string decoder omits v from its simple escape table. As a result, gettext('before\vafter') extracts the message beforevafter, 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:

  • New tests against original code: 12 failed, 3 passed.
  • Patched JavaScript lexer/extractor suites: 35 passed.
  • Full repository suite with coverage: 7,928 passed, 9 skipped, 2 xfailed, overall coverage 93%. CLDR 48.2 was downloaded, SHA-512 verified and imported using the repository's script.
  • Changed-file Ruff checks pass using the configured pre-commit version 0.14.10; git diff --check passes. No unrelated formatting changes were made.
  • Node.js independently confirms that the escape produces code point 11. Other Python/OS combinations were not validated locally.

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.

Copilot AI balanced review requested due to automatic review settings October 27, 2026 08:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 the escapes dict in babel/messages/jslexer.py.
  • Add lexer-level tests for leading/interior/trailing \v across all three delimiters, plus a test confirming a literal backslash-plus-v (\\v) is left unchanged.
  • Add an extractor-level test verifying gettext extraction 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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants