Repository navigation
fix: parse and compile \a, \b, \f and \v escapes like GNU gettext - #118
Open
zzoraemon043 wants to merge 1 commit into
Open
zzoraemon043 wants to merge 1 commit into
zzoraemon043 wants to merge 1 commit into
Conversation
GNU gettext writes the BEL, BS, FF and VT control characters as \a, \b, \f and \v in PO strings. The parser read them back as the letters a, b, f and v, so a file written by msgcat lost those characters. Unescape them when parsing and escape them when compiling with escapeCharacters, so po.compile output matches msgcat.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GNU gettext writes the BEL, BS, FF and VT control characters as
\a,\b,\fand\vin PO strings (msgcatoutput for a msgstr containing them ismsgstr "x\a\b\f\vy").po.parseonly knows\t,\nand\r, so it reads these back as the lettersa,b,fandv:This change:
\a,\b,\fand\vin the PO parserescapeCharactersis on, sopo.compileoutput matchesmsgcat(before, the raw control characters were written)Tests: a parser test and two compiler tests (escaped output, round trip). The parser test and the escaped-output test fail on master.
npm test(72) andnpm run lintpass.Also checked against GNU gettext 0.21:
msgcatoutput for 300 long entries mixing these characters with text parses and compiles back to the same file, withfoldLength: 79line breaks matchingmsgcat.Not covered: octal (
\101) and hex (\x41) escapes, which msgfmt also accepts. Those encode bytes in the file charset, which does not map directly onto the already decoded string the lexer works on.