Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apparent incompatibility between lz-string, Google Apps Script and ISO dates #124

Open
ipekarik opened this issue Dec 12, 2018 · 3 comments

Comments

@ipekarik
Copy link

ipekarik commented Dec 12, 2018

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*

@pieroxy
Copy link
Owner

pieroxy commented Jan 18, 2019

Can't reproduce it. Can you give some context? In which browser are you seeing this ?

@JobLeonard
Copy link
Collaborator

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.

@JobLeonard
Copy link
Collaborator

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 :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants