Expand mojibake repair to punctuation and symbols
This commit is contained in:
@@ -39,6 +39,27 @@ same($czech, fix(broken($czech)), 'Latin-1 mojibake, all Czech letters');
|
||||
// These letters exercise printable Windows-1252 mappings including ™, ¾ and œ.
|
||||
$windows = 'ěňřšťůžČĎĚŇŘŠŤŮŽ';
|
||||
same($windows, fix(iconv('Windows-1252', 'UTF-8', $windows)), 'Windows-1252 mojibake');
|
||||
$punctuation = array(
|
||||
'–' => '–', '—' => '—', '‘' => '‘', '’' => '’', '‚' => '‚',
|
||||
'“' => '“', "â€\u{009D}" => '”', '„' => '„', '…' => '…', '•' => '•',
|
||||
'«' => '«', '»' => '»', '‹' => '‹', '›' => '›', '€' => '€',
|
||||
'â„¢' => '™', '©' => '©', '®' => '®', '°' => '°', "Â\u{00A0}" => "\u{00A0}",
|
||||
);
|
||||
foreach ($punctuation as $damaged => $clean) {
|
||||
same($clean, fix($damaged), 'Windows-1252 punctuation: ' . $clean);
|
||||
same($clean, fix(broken($clean)), 'Latin-1 punctuation: ' . $clean);
|
||||
}
|
||||
$clean_punctuation = implode('', $punctuation);
|
||||
same($clean_punctuation, fix($clean_punctuation), 'Correct punctuation and nonbreaking space unchanged');
|
||||
$damaged_punctuation = implode('', array_keys($punctuation));
|
||||
same($clean_punctuation, fix(fix($damaged_punctuation)), 'Repeated punctuation repair is stable');
|
||||
$punctuation_settings = array('font_family' => 'Open Sans', 'label' => $damaged_punctuation);
|
||||
$punctuation_expected = array('font_family' => 'Open Sans', 'label' => $clean_punctuation);
|
||||
same(serialize($punctuation_expected), fix(serialize($punctuation_settings)), 'Punctuation repair preserves serialized typography settings');
|
||||
$punctuation_css = 'body{font-family:"Open Sans"}/* – ’ … */';
|
||||
same('body{font-family:"Open Sans"}/* – ’ … */', fix($punctuation_css), 'Punctuation in CSS preserves styling');
|
||||
$punctuation_json = '{"font":"Open Sans","url":"https:\/\/example.test","label":"– ’ …","escaped":"\\u2013"}';
|
||||
same(strtr($punctuation_json, $punctuation), fix($punctuation_json), 'Punctuation in JSON preserves escaping');
|
||||
$correct = $czech . ' 日本語 😀 € “quoted” — ß ö ñ';
|
||||
same($correct, fix($correct), 'Correct multilingual Unicode is byte-for-byte unchanged');
|
||||
same($correct . ' Příliš', fix($correct . ' ' . broken('Příliš')), 'Mixed clean and damaged text');
|
||||
|
||||
Reference in New Issue
Block a user