nullpunkt / lz-string-php

PHP Class implementation of LZ-String javascript
105 stars 54 forks source link

version compatibility between js and PHP implementation? #3

Closed aelgoa closed 8 years ago

aelgoa commented 10 years ago

js: LZString.compressToBase64(document.getElementById('src').value); php: $s=LZString::decompressFromBase64($_POST['s']);

value is caught by PHP script as intented with correct value. error happens in decompression:


Notice: Uninitialized string offset: 1123 in D:\babs\8.5\root\wwide\LZString.php on line 354

Warning: strpos() [function.strpos]: Empty delimiter in D:\babs\8.5\root\wwide\LZString.php on line 354

Fatal error: Uncaught exception 'Exception' with message '$c != $dictSize (133,128)' in D:\babs\8.5\root\wwide\LZString.php:313 Stack trace:

0 D:\babs\8.5\root\wwide\LZString.php(380): LZString::decompress('???????????????...')

1 D:\babs\8.5\root\wwide\wwc.php(6): LZString::decompressFromBase64('MQSwdgxgNgrgJgU...')

2 {main}

thrown in D:\babs\8.5\root\wwide\LZString.php on line 313

ymc-sise commented 9 years ago

I can reproduce this. Same error for me.

mattpass commented 9 years ago

I get the same issue too. Any ideas what can be done to fix it yet?

nuald commented 9 years ago

Looks like it's related to base64 encoding, 3rd party Base64 decode + LZString.decompress work correctly (so far at least, the original issue doesn't have 100% reproducibility).

ghost commented 9 years ago

If you're passing the base64 data directly via URL, the PHP decoding process replaces the pluses with spaces which are not valid base64 characters. You may need to retrieve the parameter from the query string, then replace any spaces with pluses before base64 decode or decodeFromBase64.

Escaping before passing the data may also resolve it.

nullpunkt commented 8 years ago

Hi, i've completely rewritten the PHP component to match the current algorythm / ouput provided by the javascript component. The bug is fixed in version 1.1.0.

mattpass commented 8 years ago

That's awesome - many thanks!! :+1: Definitely going to check this out.

Tarekajaj commented 8 years ago

Awesome. just tested the new version and all the (too much errors) were gone.