Open ipekarik opened 5 years ago
Can't reproduce it. Can you give some context? In which browser are you seeing this ?
I think @ipekarik is trying to use LZString from within Google App Script? I can reproduce it.
Here is a link to my example AppScript. Note that I have both 1.4.4 and 2.0RC versions:
[19-01-24 18:43:22:455 CET] Starting execution
[19-01-24 18:43:22:470 CET] console.log([{input=test-01 01-02-03, compressed=அノ살ࣀӓ栉騆戀, decompressed=test-1 1-11213}, []]) [0.002 seconds]
[19-01-24 18:43:22:472 CET] Execution succeeded [0.007 seconds total runtime]
In the not-yet-released 2.0 version this bug vanishes:
[19-01-24 18:48:31:228 CET] Starting execution
[19-01-24 18:48:31:247 CET] console.log([{input=test-01 01-02-03, compressed=அノ살À谀䜘আ٢�, decompressed=test-01 01-02-03}, []]) [0.002 seconds]
[19-01-24 18:48:31:249 CET] Execution succeeded [0.008 seconds total runtime]
Technically speaking, Google Apps Script is not JavaScript so incompatibilities are possible. Having said that, its wikipedia page claims it "is based on JavaScript 1.6 with some portions of 1.7 and 1.8 and provides subset of ECMAScript 5 API", so it looks like it should work. This might be a bug in App Script.
Anyway, assuming you are manually inlining the LZString library anyway, you might as well throw the 2.0RC version through a minifier and use that as a work-around.
Thinking of the code differences between 1.4.4 and 2.0RC, the most obvious candidate would be that LZString 1.4.4 uses a dictionary. It might be that AppScript mistakes "-0" for a 0 numerical key.
Also, when I ran this script again today 1.4.4 was fixed as well, so the behavior seems inconsistent :/
It seems that GAS somehow breaks compression/decompression of ISO dates: the hyphens from the dates are corrupted.
var decompressed = '2018-03-01';
var compressed = LZString.compress(decompressed);
decompressed = LZString.decompress(compressed);
Logger.log(decompressed); // 20180301
The same is true for compressToUTF16 and compressToBase64.
EDIT:
It seems that the problem is in the substring "-0". For example if the date is 2018-11-11, the decompressed string will contain the hyphens.
If a string contains the sequence "-0", one of two things (that I managed to identify so far) happen:
a) if the hyphen is preceded by a digit, the hyphen is lost, and the zero preserved:
10-01 -> 1001
02-02 -> 0202
b) if the hyphen is preceded by a character, the zero is lost, and the hyphen preserved:
TEST-01 -> TEST-1
TEST/-02/ -> TEST/-2/
TEST*-03* -> TEST*-3*