Skip to content

Detect Windows-1252 mojibake of U+2000-block symbols (fixes #233) - #235

Open
sebollin wants to merge 1 commit into
rspeer:mainfrom
sebollin:vulgar-fractions-233
Open

Detect Windows-1252 mojibake of U+2000-block symbols (fixes #233)#235
sebollin wants to merge 1 commit into
rspeer:mainfrom
sebollin:vulgar-fractions-233

Conversation

@sebollin

Copy link
Copy Markdown

Fixes#233.

fix_encoding("â…“") returns the input unchanged instead of . The bytes are E2 85 93, which is the UTF-8 encoding of U+2153 read as Windows-1252. The heuristic misses it because the second byte lands in common, and common is deliberately not treated as evidence on its own.

The obvious general rule doesn't work. I started with

[{lower_accented}{upper_accented}] [{common}] [punctuation]

and it fails the negative case that's already in the suite for exactly this shape:

Synthetic, negative: Brontë's name does not end with a Korean syllable
"…Charlotte Brontë…”" -> "…Charlotte Bront녔"

ë…” and â…“ are the same shape. What separates them is the lead byte: â is 0xE2, which opens the punctuation and symbol blocks, while ë is 0xEB, which opens Hangul.

So I restricted the new alternative to â, in the same spirit as the existing rule that is restricted to [ÂÃÎÐ] rather than to a whole category. Brontë is left alone, â…“ and â…› come out right, and the suite goes from 351 to 353 passing with the same 10 xfails.

fix_encoding("â…“") returned the input unchanged instead of "⅓". The bytes
are E2 85 93, the UTF-8 encoding of U+2153, read as Windows-1252. The
badness heuristic misses it because the second byte lands in the "common"
category, which is deliberately not treated as evidence on its own.
The obvious general rule -- [accented] [common] [punctuation] -- cannot be
used: it also matches "Charlotte Brontë…”", which the test suite already
guards against with a named negative case, and would turn it into a Korean
syllable. The difference is the lead byte: 'â' is 0xE2, which opens the
punctuation and symbol blocks, while 'ë' is 0xEB, which opens Hangul.
So the new alternative is restricted to 'â', in the same spirit as the
existing rule that is restricted to [ÂÃÎÐ] rather than to a whole category.
Sign up for freeto 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.

Characters not converted

1 participant

@sebollin