Skip to content

File's content transformed in to "false" content Β #695

@ivarsg

Description

@ivarsg

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:

$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,

  1. 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 $encoding holds false value);
  2. 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 to iconv() documentation it returns FALSE and this is how on line No 107 file's content is converted to single word "false".
  3. 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 in mb_detect_encoding() are documented under mb_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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions