Skip to content

Correct way to parse foreign character file names #15

@t123yh

Description

@t123yh

I'm using Chinese Windows and the default name for a new directory is "新建文件夹".
However, after creating the directory the characters turned out to be "鏂板缓鏂囦欢澶?" which is a complete mess. The file name in Linux is correct.

I tried to change line 727 of DokanOperations.cs from

fi.FileName = entry.getFilename();

to

fi.FileName = Encoding.UTF8.GetString(Encoding.Default.GetBytes(Encoding.UTF8.GetString(entry.getFilename().getBytes()))); // Encoding.Default in Chinese Windows is GB2312

and got "新建文件�?" which is nearly correct but the last character is broken.

In the above example, entry.getFilename().getBytes() for "新建文件夹" is as follows:

entry.getFilename().getBytes()
{byte[22]}
    [0]: 233
    [1]: 143
    [2]: 130
    [3]: 230
    [4]: 157
    [5]: 191
    [6]: 231
    [7]: 188
    [8]: 147
    [9]: 233
    [10]: 143
    [11]: 130
    [12]: 229
    [13]: 155
    [14]: 166
    [15]: 230
    [16]: 172
    [17]: 162
    [18]: 230
    [19]: 190
    [20]: 182
    [21]: 63

I created a directory named "新"(a single character), and found entry.getFilename().getBytes() is only a byte long. Obviously it is truncated.

{byte[1]}
    [0]: 46

So I doubt there are some problems with SharpSSH.

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