Skip to content

Commit fbab537

Browse files
authored
Merge pull request #27 from Crizz0/issue/23
Add if-sentence to detect UTF8 files and handle them differently than…
2 parents fb19579 + 8bef16f commit fbab537

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

controller/main.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,18 @@ private function display_pb()
311311

312312
if (!$file->error)
313313
{
314-
$snippet_contents = utf8_normalize_nfc(utf8_convert_message(@file_get_contents($file->get('filename'))));
314+
// Well, ugly solutions work, too
315+
$snippet_contents = @file_get_contents($file->get('filename'));
316+
// Check for UTF-8 encoding; because utf8_convert_message() will destroy utf8-characters in UTF-8 documents
317+
if (mb_detect_encoding($snippet_contents, 'UTF-8', true))
318+
{
319+
$snippet_contents = utf8_normalize_nfc($snippet_contents);
320+
}
321+
// e.g. ISO 8859-1 encoded files need the utf8_convert_message()
322+
else
323+
{
324+
$snippet_contents = utf8_normalize_nfc(utf8_convert_message($snippet_contents));
325+
}
315326
}
316327

317328
$file->remove();

0 commit comments

Comments
 (0)