Skip to content

Respect source encoding in JavaScript template extraction - #1443

Merged
akx merged 1 commit into
python-babel:masterfrom
tanveerchana:fix/js-template-source-encoding
Nov 9, 2026
Merged

akx merged 1 commit into
python-babel:masterfrom
tanveerchana:fix/js-template-source-encoding

Conversation

@tanveerchana

Copy link
Copy Markdown
Contributor

JavaScript source is decoded with the configured encoding. The template interpolation extractor then encodes each expression as UTF-8 and passes it to a recursive extraction call that decodes with the original encoding. In a Latin-1 file this turns café into café. In a UTF-16LE file the message is lost.

Use the configured source encoding for the fragment passed to the recursive extractor. The regression test checks that the same literal is extracted both directly and from a template expression, with the original line numbers, for UTF-8, Latin-1, and UTF-16LE. This was found while investigating #989 and is independent of the quote-handling change in #1285.

Validation on CPython 3.12 / Linux

  • Before the fix, the Latin-1 and UTF-16LE cases failed. 18 tests passed in tests/messages/test_js_extract.py.
  • After the fix, 26 tests passed across JavaScript extraction and lexing.
  • python -X utf8 -m pytest -q --tb=short with generated CLDR 49 data reported 8,213 passed, 7 skipped, and 2 xfailed.
  • Ruff 0.14.10 on both changed files and git diff --check passed.Re-encode extracted interpolation fragments using the encoding that the recursive extractor will use to read them.

Re-encode extracted interpolation fragments using the encoding that the
recursive extractor will use to read them.
@akx akx added the AI Assisted label Nov 9, 2026

@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.

Sure, why not.

@akx akx added bug area/javascript JavaScript extractor labels Nov 9, 2026
@akx
akx enabled auto-merge (squash) November 9, 2026 10:51
@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.62%. Comparing base (a18709c) to head (5b4d451).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1443   +/-   ##
=======================================
  Coverage   93.62%   93.62%           
=======================================
  Files          27       27           
  Lines        4973     4973           
=======================================
  Hits         4656     4656           
  Misses        317      317           
Flag Coverage Δ
macos-15-3.10 92.70% <100.00%> (?)
macos-15-3.11 92.64% <100.00%> (?)
macos-15-3.12 92.90% <100.00%> (?)
macos-15-3.13 92.90% <100.00%> (ø)
macos-15-3.14 92.88% <100.00%> (?)
macos-15-3.15 92.88% <100.00%> (ø)
macos-15-3.9 92.63% <100.00%> (?)
macos-15-pypy3.10 92.70% <100.00%> (?)
ubuntu-24.04-3.10 92.72% <100.00%> (ø)
ubuntu-24.04-3.11 92.66% <100.00%> (ø)
ubuntu-24.04-3.12 92.92% <100.00%> (?)
ubuntu-24.04-3.13 92.92% <100.00%> (ø)
ubuntu-24.04-3.14 92.90% <100.00%> (ø)
ubuntu-24.04-3.15 92.90% <100.00%> (ø)
ubuntu-24.04-3.9 92.65% <100.00%> (ø)
ubuntu-24.04-pypy3.10 92.72% <100.00%> (ø)
windows-2022-3.10 92.71% <100.00%> (ø)
windows-2022-3.11 92.65% <100.00%> (?)
windows-2022-3.12 92.91% <100.00%> (?)
windows-2022-3.13 92.91% <100.00%> (?)
windows-2022-3.14 92.89% <100.00%> (?)
windows-2022-3.15 92.89% <100.00%> (ø)
windows-2022-3.9 92.64% <100.00%> (ø)
windows-2022-pypy3.10 92.71% <100.00%> (?)

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 Nov 9, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 88 untouched benchmarks


Comparing tanveerchana:fix/js-template-source-encoding (5b4d451) with master (a18709c)

Open in CodSpeed

@akx
akx merged commit 93846a2 into python-babel:master Nov 9, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants