Skip to content

Escape header values in PoGenerator - #315

Merged
oscarotero merged 1 commit into
php-gettext:masterfrom
jayhemnani9910:fix/po-escape-headers
Nov 24, 2026
Merged

oscarotero merged 1 commit into
php-gettext:masterfrom
jayhemnani9910:fix/po-escape-headers

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

PoGenerator writes header values without escaping them. A PO file whose Last-Translator has a quoted name, as Weblate writes it when the name has a dot or comma, is saved in a form GNU gettext rejects:

"Last-Translator: \"Josep M. Ferrer\" <txemaq@gmail.com>\n"
$t = (new PoLoader())->loadFile('ca.po');
$t->add(Translation::create(null, 'New string'));
(new PoGenerator())->generateFile($t, 'ca.out.po');

The saved line is "Last-Translator: "Josep M. Ferrer" <txemaq@gmail.com>\n", and msgfmt -c ca.out.po fails with keyword "Josep" unknown and syntax error. Poedit won't open it either. PoLoader reads it back leniently, so the round trip inside the library looks fine. Round-tripping the .mo files in /usr/share/locale here, 5 of 289 catalogs had such a header.

Every other string goes through encode(), but the header lines were built with sprintf('"%s: %s\n"'). They now go through encode() too, which gives the same output for ordinary headers.

Added testHeaderValuesAreEscaped, which fails without the change. phpunit passes (107 tests), and the file above passes msgfmt -c after the round trip.

@oscarotero
oscarotero merged commit 1d5bf78 into php-gettext:master Nov 24, 2026
11 checks passed
@oscarotero

Copy link
Copy Markdown
Member

thank you!

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