rufushuang / lz-string4java

Port javascript lz-string in JAVA version. Done some of language optimization. And a rhino side for Testing.
MIT License
46 stars 22 forks source link

Cannot decompressFromUTF16 strings received from Safari #4

Closed carminexx closed 9 years ago

carminexx commented 9 years ago

Hi, I'm using lz-string4java to decompress UTF16 strings, created with the original Javascript library LZString, on a webpage. These strings are then sent via XMLHttpRequests. On Chrome, Firefox, etc., everything works as expected. On Safari, the UTF16 is correctly received from the XMLHttpRequest, but when I try to decode the content with LZString.decompressFromUTF16, the lz-string4java library fails, and I got a "null" as result. I think Safari handles UTF16 differently from other browsers, and, in fact, I noticed small differences for some characters, between the javascript UTF16 string, and the actual UTF16 string passed to lz-string4java. Is this a bug on lz-string4java, or a limitation of Safari UTF16 implementation?

rufushuang commented 9 years ago

Can u pass the test with your string in rufus.lzstring4javarhinotest.LZStringTest? If pass, it maybe something wrong with safari.

then you can ask for javascript version lz-string? @pieroxy

pieroxy commented 9 years ago

One of the common problem with UTF transmission is that some kind of normalization can take place. Many characters appear twice and are considered equivalent from a "string" perspective. Since LZ-String use those strings as a kind of binary transport, swapping two characters breaks the binary stream and the string cannot be decompressed.

The proper way to get bytes out of the browser is to use compressToEncodedURIComponent as discussed in https://github.com/pieroxy/lz-string/issues/60

It might be slightly less efficient, but it works reliably as it uses only ASCII characters. The corresponding decompressFromEncodedURIComponent is in lz-string4java.

rufushuang commented 9 years ago

So far there is no any further progress on pieroxy's issue 60 mentioned above. I think I should close this issue down