-
Notifications
You must be signed in to change notification settings - Fork 42
Open
Description
When I try to open file for editing with "Edit in Plain Text editor", whatever is the actual content of the file, the content in text editor is just one word - "false".
After some research I came to these lines of source code, and there is, in my opinion something wrong:
files_texteditor/lib/Controller/FileHandlingController.php
Lines 99 to 107 in 6b4e0e1
| $encoding = mb_detect_encoding($fileContents . 'a', 'UTF-8, WINDOWS-1252, ISO-8859-15, ISO-8859-1, ASCII', true); | |
| if ($encoding === '') { | |
| // set default encoding if it couldn't be detected | |
| $encoding = 'ISO-8859-15'; | |
| } | |
| $fileContents = iconv($encoding, 'UTF-8', $fileContents); | |
| return new DataResponse( | |
| [ | |
| 'filecontents' => $fileContents, |
- since in line No 99 it is strict mode used,
mb_detect_encoding()function will return either one of the encodings given in the input list, or FALSE; in case of FALSE or any valid result, the condition on line No 100 will NEVER evaluate to TRUE (some times in history, here was simple comparison, and in this case it evaluated to TRUE in case if$encodingholds false value); - in case if
iconv()function fails on line No 104 (as it is in may case; I can read error logs in NC logs), according toiconv()documentation it returns FALSE and this is how on line No 107 file's content is converted to single word "false". - as per this answer on stackoverflow.com, most probably on line No 99 the passed in encoding list is not correct/supported by
mb_detect_encoding()(here I agree that PHP documentation is a bit awkward - encodings currently implemented inmb_detect_encoding()are documented undermb_detect_order())
In my case valid UTF-8 content is detected as WINDOWS-1257, and then iconv() fails to convert actual UTF8 content treated as WINDOWS-1257 to UTF8. There is an error log entry in NC logs: Error: iconv(): Detected an illegal character in input string at /var/www/{******}/apps/files_texteditor/lib/Controller/FileHandlingController.php#104
midcode, red3333 and clorenz150
Metadata
Metadata
Assignees
Labels
No labels