Coder Social home page Coder Social logo

Comments (8)

rquadling avatar rquadling commented on May 20, 2024
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.

dgstpierre avatar dgstpierre commented on May 20, 2024

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.

rquadling avatar rquadling commented on May 20, 2024

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.

dgstpierre avatar dgstpierre commented on May 20, 2024

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.

pieroxy avatar pieroxy commented on May 20, 2024

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.

dgstpierre avatar dgstpierre commented on May 20, 2024

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.

pieroxy avatar pieroxy commented on May 20, 2024

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?

from lz-string.

dgstpierre avatar dgstpierre commented on May 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.