PDA

View Full Version : [FIXED] Does fromQueryString have a bug in it?



mark0978
11 Apr 2013, 8:11 PM
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Object-method-fromQueryString

If you have a string like:

"doctypes=Correspondence&doctypes=Line+Item" it will decode it into:



Ext.Object.fromQueryString("doctypes=Correspondence&doctypes=Line+Item")
Object {doctypes: Array[2]}
doctypes: Array[2]
0: "Correspondence"
1: "Line+Item"
length: 2


It fails to convert the + to a space as expected. This is similar to decodeURIComponent, but I had expected it to behave more like the Python parse_qsl()

The reason I ask is because if you extend that string just a bit:

"doctypes=Correspondence&doctypes=Line+Item%2B" it will decode the second doctypes element as Line+Item+ and at this point, I can't just regex replace the + with a space any longer.

My workaround at the moment is to do the regex replace FIRST



Ext.Object.fromQueryString("doctypes=Correspondence&doctypes=Line+Item%2b".replace(/\+/g,' '))


which does give the right answer, but I'm wondering if I'm missing some edge case.

mitchellsimoens
12 Apr 2013, 7:26 AM
IMO it needs to adhere to the standard as a space can either be '%20' or '+'. A pretty good reference is at http://www.w3schools.com/tags/ref_urlencode.asp (w3schools.com isn't the most accurate but this list is a pretty good reference).

mark0978
12 Apr 2013, 7:33 AM
Ok, but doesn't fromQueryString mean that it has been translated fromQueryString? You are building a dict of values from the querystring keyed by its values.

In fact I think your statement might have helped in the argument that it is a bug:


Ext.Object.fromQueryString("foo=This+is%20a%20test")
Object {foo: "This+is a test"}


The plus survives the fromQueryString but the %20 is converted. This seems to indicate the + should be converted during fromQueryString.

mitchellsimoens
12 Apr 2013, 7:44 AM
Do note that I moved this to the bugs forum and it is marked as open already.