Comments (8)
var test = LZString.compressToEncodedURIComponent("This is a string of very long length that seems to be having a lot of suggestions from the Chrome console as to what I will type next. And so I need to add a LOT more text!!!!!!!!!!!!!!!!!!!!!!!! Added!!!!");
LZString.decompressFromEncodedURIComponent(test);
outputs
This is a string of very long length that seems to be having a lot of suggestions from the Chrome console as to what I will type next. And so I need to add a LOT more text!!!!!!!!!!!!!!!!!!!!!!!! Added!!!!
In your example, the spaces around the +
seem the issue.
"{"ei":"ev1-1","rqi":"rq1+1","sei":"sev1$1","cc":"US","ri":"resp1","si":"1","vt":"oQUHwV2u8h8HfCG+F6DldNrMeSCt3N6b5vHSURcyJxg=","pi":"20,0,0,272|5,1,41212,0|enabled|11,0,0,0||||||||","dp":"America/New_York|2560X1440|24-24|true|Win32|1899|324||0|Thu Jan 28 13:51:40 EST 2016|300|en-US|true|true|5gZ2gMlDHQ1CC4Qka8vlPSFrUoJ4RFsiLJFNDgcZKU4=|5gZ2gMlDHQ1CC4Qka8vlPT/sQ993Dpa1x6qOTWZY0gw=||false","ep":"|1||0|0|2560|1387|2|f7a3692ae25b3f494186f6f059040c9f|0|0|2|0|2|0|||0","vp":{"em":"[email protected]","ph":null,"ste":"51 Lyons Way","ci":"North Andover","st":"MA","pc":"01845","dm":"truesample.com","nm":"David St. Pierre","ws":"http://www.truesample.com"},"dc":[1,2],"tr":true}"
is what I get with the spaces removed.
from lz-string.
The result you get is correct, thanks for the quick response. I’m trying to pass json strings over a rest api using jsonp, which requires passing the data as a query string parameter. Do I need to do something to the json string or is there a fix to the javascript code to support it?
Thanks,
David
From: Richard Quadling [mailto:[email protected]]
Sent: Friday, January 29, 2016 9:04 AM
To: pieroxy/lz-string [email protected]
Cc: David St. Pierre [email protected]
Subject: Re: [lz-string] decompressFromEncodeURIComponent fails (#72)
var test = LZString.compressToEncodedURIComponent("This is a string of very long length that seems to be having a lot of suggestions from the Chrome console as to what I will type next. And so I need to add a LOT more text!!!!!!!!!!!!!!!!!!!!!!!! Added!!!!");
LZString.decompressFromEncodedURIComponent(test);
outputs
This is a string of very long length that seems to be having a lot of suggestions from the Chrome console as to what I will type next. And so I need to add a LOT more text!!!!!!!!!!!!!!!!!!!!!!!! Added!!!!
In your example, the spaces around the + seem the issue.
"{"ei":"ev1-1","rqi":"rq1+1","sei":"sev1$1","cc":"US","ri":"resp1","si":"1","vt":"oQUHwV2u8h8HfCG+F6DldNrMeSCt3N6b5vHSURcyJxg=","pi":"20,0,0,272|5,1,41212,0|enabled|11,0,0,0||||||||","dp":"America/New_York|2560X1440|24-24|true|Win32|1899|324||0|Thu Jan 28 13:51:40 EST 2016|300|en-US|true|true|5gZ2gMlDHQ1CC4Qka8vlPSFrUoJ4RFsiLJFNDgcZKU4=|5gZ2gMlDHQ1CC4Qka8vlPT/sQ993Dpa1x6qOTWZY0gw=||false","ep":"|1||0|0|2560|1387|2|f7a3692ae25b3f494186f6f059040c9f|0|0|2|0|2|0|||0","vp":{"em":"[email protected]:[email protected]","ph":null,"ste":"51 Lyons Way","ci":"North Andover","st":"MA","pc":"01845","dm":"truesample.com","nm":"David St. Pierre","ws":"http://www.truesample.com"},"dc":[1,2],"tr":true}" is what I get with the spaces removed.
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/72#issuecomment-176767449.
from lz-string.
If you are passing it as a query string, then the URI escaping of the spaces is getting in the way. It may be better to pass it in the body of the POST rather than in the URL.
from lz-string.
I can’t pass it in the body with a jsonp call, it’s not supported (not officially, and it doesn’t work on all browsers if you attempt it). And with this being a cross-domain api call it has to be either jsonp or cors (which does support posts), but cors isn’t supported on older browsers.
If I don’t compress it and simply call encodeURIComponent then it works… but then I don’t get the compression… not sure why spaces are a problem for the compression?
Thanks
From: Richard Quadling [mailto:[email protected]]
Sent: Friday, January 29, 2016 9:15 AM
To: pieroxy/lz-string [email protected]
Cc: David St. Pierre [email protected]
Subject: Re: [lz-string] decompressFromEncodeURIComponent fails (#72)
If you are passing it as a query string, then the URI escaping of the spaces is getting in the way. It may be better to pass it in the body of the POST rather than in the URL.
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/72#issuecomment-176776035.
from lz-string.
The URI escaping is just (If I understand the issue correctly) converting '+' to spaces. A quick fix for you might be to convert all spaces to '+' before trying to decompress the String.
As this is a common problem, I might include this behavior in the lib. I'm just waiting for you to confirm that it would solve the issue.
from lz-string.
You already perform this in the decompress method right before the _decompress call or am I misunderstanding?
//decompress from an output of compressToEncodedURIComponent
decompressFromEncodedURIComponent:function (input) {
if (input == null) return "";
if (input == "") return null;
input = input.replace(/ /g, "+");
return LZString._decompress(input.length, 32, function(index) { return getBaseValue(keyStrUriSafe, input.charAt(index)); });
},
From: pieroxy [mailto:[email protected]]
Sent: Saturday, January 30, 2016 11:07 AM
To: pieroxy/lz-string [email protected]
Cc: David St. Pierre [email protected]
Subject: Re: [lz-string] decompressFromEncodeURIComponent fails (#72)
The URI escaping is just (If I understand the issue correctly) converting '+' to spaces. A quick fix for you might be to convert all spaces to '+' before trying to decompress the String.
As this is a common problem, I might include this behavior in the lib. I'm just waiting for you to confirm that it would solve the issue.
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/72#issuecomment-177220613.
from lz-string.
In the example you posted, you have in effect " + " in some part of your input. This doesn't seem right. The space character is not used in the compressToEncodedURIComponent
method. They could appear through URL encoding, but then they would replace the "+" character which would have been converted. In the input you provide to LZString.decompressFromEncodedURIComponent
there are spaces AND + characters. I would bet this is not what came out of compressToEncodedURIComponent
, hence the inability for the decompressor to decompress it. Can you try to understand where those spaces come from?
from lz-string.
Thanks for your help on this. You are correct, I made a mistake and grabbed the string after it came over to the server. When I retested just on the client side it worked. Thanks again!
From: pieroxy [mailto:[email protected]]
Sent: Sunday, January 31, 2016 3:24 AM
To: pieroxy/lz-string [email protected]
Cc: David St. Pierre [email protected]
Subject: Re: [lz-string] decompressFromEncodeURIComponent fails (#72)
In the example you posted, you have in effect " + " in some part of your input. This doesn't seem right. The space character is not used in the compressToEncodedURIComponent method. They could appear through URL encoding, but then they would replace the "+" character which would have been converted. In the input you provide to LZString.decompressFromEncodedURIComponentthere are spaces AND + characters. I would bet this is not what came out of compressToEncodedURIComponent, hence the inability for the decompressor to decompress it. Can you try to understand where those spaces come from?
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/72#issuecomment-177430127.
from lz-string.
Related Issues (20)
- Newbie question: How would I go about downloading / uploading a file? HOT 2
- Does `compressToUint8Array()` output smaller than `compress()` ? HOT 1
- Quotes in the compressed string HOT 3
- Implement IRI Encoding HOT 1
- Bug: can not decompress for some compressed string HOT 4
- Crash with large strings when running on Hermes (React Native)
- Is there a way to allow custom dictionaries? HOT 9
- How to realize that only specified characters are allowed to appear in the compression result? HOT 1
- LZ-String port to current typescript HOT 9
- Tag for v1.5.0 HOT 2
- Version 2 TODO list HOT 15
- Feature request: compress to source-compatible character set HOT 1
- New port for a linux executable HOT 1
- Can utf-8 codes be avoided in the output? HOT 10
- `decompressFromBase64` can return `null` HOT 7
- Docs: JSPerf.com links are no longer valid
- Docs: A Complete Demo for various compression/decompression HOT 3
- Docs: TSDoc HOT 3
- License Inconsistencies HOT 5
- Community Question: Breaking Changes and Version 2! HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lz-string.