pwlin / cordova-plugin-file-opener2

A File Opener Plugin for Cordova
MIT License
318 stars 587 forks source link

Non ASCII characters in filename --> file not found #190

Open polfdz opened 6 years ago

polfdz commented 6 years ago

The plugin fails when trying to open a file with an accent like tèst.pdf, however if I rename it to test.pdf it opens.

The error thrown is: {status: 9, message: "File not found"} Is there any solution?

Thanks in advance

BrunoMinami commented 6 years ago

Since there's no official solution, I'm using a function to remove all "special" characters from filename. There's also a problem with the file name lenght, that's why it gets only the first 100 characters.

function parseFilename(originalString) {
    var parsed = originalString.substring(0, 100);
    var specialChars = {
        a: /[\xE0-\xE6]/g,
        A: /[\xC0-\xC6]/g,
        e: /[\xE8-\xEB]/g,
        E: /[\xC8-\xCB]/g,
        i: /[\xEC-\xEF]/g,
        I: /[\xCC-\xCF]/g,
        o: /[\xF2-\xF6]/g,
        O: /[\xD2-\xD6]/g,
        u: /[\xF9-\xFC]/g,
        U: /[\xD9-\xDC]/g,
        c: /\xE7/g,
        C: /\xC7/g,
        n: /\xF1/g,
        N: /\xD1/g,
        _: /[^A-Za-z0-9.]/g
    };

    for (var char in specialChars) {
        var regEx = specialChars[char];
        parsed = parsed.replace(regEx, char);
    }

    return parsed;
}
shnist commented 5 years ago

@polfdz i believe this was fixed in 2.2.0. Can you confirm the issue is resolved for you in this version?

ThodorisElissaios commented 5 years ago

the problem still exists ... file with Greek chars throws {status: 9, message: "File not found"}

shnist commented 5 years ago

yes looks like this issue still exists as all non ASCII characters seem to throw this error. I'm going to close https://github.com/pwlin/cordova-plugin-file-opener2/issues/252 as a duplicate and perhaps pin this issue for now as it seems to be one of the more significant bugs in this plugin.

pwlin commented 5 years ago

Can this be an encoding issue with how Java or Objective-C works? Because this plugin does not do anything special.

The way fileName has been constructed must be wrong because the immediate line check for the existence of the file.

https://github.com/pwlin/cordova-plugin-file-opener2/blob/f7e1da9f1466e8b21312d77016e50e7757eb4cec/src/android/io/github/pwlin/cordova/plugins/fileopener2/FileOpener2.java#L93-L103

If you look back in the git history, you'll see that this has been changed through merging pull requests.

Does Java's File object accept an encoding type?

Queenhy commented 5 years ago

I have the same problem with german characters ß, ä, ö and ü.