Skip to content

pofile: Unescape the C escapes GNU gettext writes - #1425

Merged
akx merged 1 commit into
python-babel:masterfrom
chrikrah:fix/unescape-gnu-c-escapes
Nov 4, 2026
Merged

akx merged 1 commit into
python-babel:masterfrom
chrikrah:fix/unescape-gnu-c-escapes

Conversation

@chrikrah

@chrikrah chrikrah commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

PO strings use C escapes (GNU manual); xgettext writes VT as \v, likewise \a, \b, \f. read_po keeps these as two characters, so Babel's .mo misses the translation. No issue exists.

$ xgettext --version | head -1
xgettext (GNU gettext-tools) 0.21
$ cat de.po   # header omitted
msgid "col1\vcol2"
msgstr "Spalte1\vSpalte2"
$ python repro.py   # read_po + write_mo, then gettext.GNUTranslations, at 7576e5d
'col1\x0bcol2'  GNU msgfmt: 'Spalte1\x0bSpalte2'  | babel write_mo: 'col1\x0bcol2'
$ python repro.py   # with this patch
'col1\x0bcol2'  babel write_mo: 'Spalte1\x0bSpalte2'
$ python -X utf8 -m pytest -q   # 7576e5d: 6766 passed, 1181 skipped, 1 xfailed
6768 passed, 1181 skipped, 1 xfailed, 1 warning in 10.63s
$ python -m pytest -q tests/messages/test_pofile.py -k "unescape or vertical"   # fix reverted, tests kept
2 failed, 2 passed, 40 deselected
$ ruff check babel/messages/pofile.py tests/messages/test_pofile.py   # ruff 0.14.10
All checks passed!
$ python -c "from babel.messages import pofile as p; print(repr(p.normalize(p.unescape(r'\"col1\vcol2\"'), prefix='msgid ')))"   # write side, with this patch
'""\nmsgid "col1\x0b"\nmsgid "col2"'
# not run: tox across Python versions, Windows

escape() has the same gap: write_po now emits a raw VT, not \v. I'd fix it here with a round-trip test, skipping octal and \x. OK?

GNU xgettext and msgcat write BEL, BS, FF and VT inside PO strings as
\a, \b, \f and \v. read_po only decoded \n, \r, \t, \\ and \", so these
four stayed as a backslash and a letter, and a catalog compiled by
Babel looked the message up under the wrong msgid.

Signed-off-by: Christopher Krah <48338417+chrikrah@users.noreply.github.com>

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

Expanding the list of escaped characters to match a couple more usual suspects. Sure.

@akx
akx enabled auto-merge (squash) November 4, 2026 06:07
@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.61%. Comparing base (7576e5d) to head (61002ea).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1425      +/-   ##
==========================================
+ Coverage   93.57%   93.61%   +0.03%     
==========================================
  Files          27       27              
  Lines        4951     4946       -5     
==========================================
- Hits         4633     4630       -3     
+ Misses        318      316       -2     
Flag Coverage Δ
macos-14-3.10 92.64% <100.00%> (+0.03%) ⬆️
macos-14-3.11 92.57% <100.00%> (+0.03%) ⬆️
macos-14-3.12 92.84% <100.00%> (+0.03%) ⬆️
macos-14-3.13 92.84% <100.00%> (+0.03%) ⬆️
macos-14-3.14 92.82% <100.00%> (+0.03%) ⬆️
macos-14-3.15 92.82% <100.00%> (+0.03%) ⬆️
macos-14-3.8 92.51% <100.00%> (+0.03%) ⬆️
macos-14-3.9 92.57% <100.00%> (+0.03%) ⬆️
macos-14-pypy3.10 92.64% <100.00%> (+0.03%) ⬆️
ubuntu-24.04-3.10 92.66% <100.00%> (+0.03%) ⬆️
ubuntu-24.04-3.11 92.60% <100.00%> (+0.03%) ⬆️
ubuntu-24.04-3.12 92.86% <100.00%> (+0.03%) ⬆️
ubuntu-24.04-3.13 92.86% <100.00%> (+0.03%) ⬆️
ubuntu-24.04-3.14 92.84% <100.00%> (+0.03%) ⬆️
ubuntu-24.04-3.15 92.84% <100.00%> (+0.03%) ⬆️
ubuntu-24.04-3.8 92.53% <100.00%> (+0.03%) ⬆️
ubuntu-24.04-3.9 92.59% <100.00%> (+0.03%) ⬆️
ubuntu-24.04-pypy3.10 92.66% <100.00%> (+0.03%) ⬆️
windows-2022-3.10 92.65% <100.00%> (+0.03%) ⬆️
windows-2022-3.11 92.59% <100.00%> (+0.03%) ⬆️
windows-2022-3.12 92.85% <100.00%> (+0.03%) ⬆️
windows-2022-3.13 92.85% <100.00%> (+0.03%) ⬆️
windows-2022-3.14 92.83% <100.00%> (+0.03%) ⬆️
windows-2022-3.15 92.83% <100.00%> (+0.03%) ⬆️
windows-2022-3.8 92.62% <100.00%> (+0.03%) ⬆️
windows-2022-3.9 92.58% <100.00%> (+0.03%) ⬆️
windows-2022-pypy3.10 92.65% <100.00%> (+0.03%) ⬆️

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 4, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 88 untouched benchmarks


Comparing chrikrah:fix/unescape-gnu-c-escapes (61002ea) with master (7576e5d)

Open in CodSpeed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants