Skip to content

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

Merged
akx merged 2 commits into
python-babel:masterfrom
Dcastroro:fix/decode-javascript-vertical-tab-escapes
Oct 30, 2026
Merged

akx merged 2 commits into
python-babel:masterfrom
Dcastroro:fix/decode-javascript-vertical-tab-escapes

Conversation

@Dcastroro

Copy link
Copy Markdown
Contributor

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

@akx
akx force-pushed the fix/decode-javascript-vertical-tab-escapes branch from 6227a64 to 4de1dd2 Compare October 30, 2026 10:02

@akx akx 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. I took the liberty of removing some unnecessary tests.

@akx
akx enabled auto-merge (squash) October 30, 2026 10:04
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.55%. Comparing base (1fcf0d1) to head (4de1dd2).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1409      +/-   ##
==========================================
+ Coverage   93.52%   93.55%   +0.02%     
==========================================
  Files          27       27              
  Lines        4930     4931       +1     
==========================================
+ Hits         4611     4613       +2     
+ Misses        319      318       -1     
Flag Coverage Δ
macos-14-3.10 92.63% <100.00%> (+0.02%) ⬆️
macos-14-3.11 92.57% <100.00%> (+0.02%) ⬆️
macos-14-3.12 92.78% <100.00%> (+0.02%) ⬆️
macos-14-3.13 92.78% <100.00%> (+0.02%) ⬆️
macos-14-3.14 92.76% <100.00%> (+0.02%) ⬆️
macos-14-3.15 92.76% <100.00%> (+0.02%) ⬆️
macos-14-3.8 92.51% <100.00%> (+0.02%) ⬆️
macos-14-3.9 92.57% <100.00%> (+0.02%) ⬆️
macos-14-pypy3.10 92.63% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.10 92.65% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.11 92.59% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.12 92.80% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.13 92.80% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.14 92.78% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.15 92.78% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.8 92.53% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.9 92.59% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-pypy3.10 92.65% <100.00%> (+0.02%) ⬆️
windows-2022-3.10 92.65% <100.00%> (+0.02%) ⬆️
windows-2022-3.11 92.59% <100.00%> (+0.02%) ⬆️
windows-2022-3.12 92.79% <100.00%> (+0.02%) ⬆️
windows-2022-3.13 92.79% <100.00%> (+0.02%) ⬆️
windows-2022-3.14 92.77% <100.00%> (+0.02%) ⬆️
windows-2022-3.15 92.77% <100.00%> (+0.02%) ⬆️
windows-2022-3.8 92.62% <100.00%> (+0.02%) ⬆️
windows-2022-3.9 92.58% <100.00%> (+0.02%) ⬆️
windows-2022-pypy3.10 92.65% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed

codspeed Bot commented Oct 30, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 88 untouched benchmarks


Comparing Dcastroro:fix/decode-javascript-vertical-tab-escapes (4de1dd2) with master (2520810)

Open in CodSpeed

@akx
akx merged commit 0d2b263 into python-babel:master Oct 30, 2026
36 checks passed
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