Skip to content

Handling filesystems with non-Unicode filenames #8134

Description

@Aurel300

Many filesystems allow filenames in the format:

Any byte except NUL, / (ext4)

or even:

Any byte except : (MFS)

Both NTFS, ReFS (Windows) and HFS+ (macOS) impose a fairly reasonable limitation:

Any Unicode except NUL, / (ReFS)

With an only-Unicode paths limitation, we can express paths as Unicode Strings in Haxe and have nice FileSystem interfaces. Since we support Linux, however, there is a potential problem when running on e.g. ext4 and needing to read or write into a file with a name that is not a valid Unicode string.

(Tested on RC.2, Ubuntu 14.04 on an ext4 filesystem.) The behaviour atm is very inconsistent across targets:

$ mkdir invalid
$ cd invalid
$ touch `printf "\xc3\x28"` # (this creates a file with a Unicode-invalid filename)
class Test {
  public static function main():Void {
    trace(sys.FileSystem.readDirectory("invalid")[0].charCodeAt(0));
  }
}

On eval, filename.charCodeAt(0) == 232
On neko, filename.charCodeAt(0) == 195
On PHP, filename.charCodeAt(0) == 104
On Python, filename.charCodeAt(0) == 56515 (AND it thinks the String is valid Unicode, i.e. Python sanitised it before Haxe got it)
On JS (node), filename.charCodeAt(0) == 65533

The proposed solution by @ncannasse was to have a scheme for "escaping" and "unescaping" paths between the filesystem and Haxe. Any invalid Unicode sequence would be replaced by a special Unicode character followed by the original byte turned into a Unicode point, i.e. "<invalid byte 7E>" -> "<escape character><unicode character U+007E>" (note that U+007E is not the same as the byte 7E).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions