PolymerElements / iron-location

A Polymer element that manages binding to the page's URL.
22 stars 41 forks source link

Support query params containing + instead of %20 #46

Closed palli closed 8 years ago

palli commented 8 years ago

Internally uses decodeUriComponent to decode query string into a javascript object. Turns out upon investigation that decodeUriComponent does not handle all forms of valid encodings, only the ones produced by encodeUriComponent.

Encoding a space into + instead of %20 is relatively common (in query string only, not full urls) and perfectly valid according to https://en.wikipedia.org/wiki/Query_string#URL_encoding

This patch adds a special case around decodeUriComponent so it also handles + in the query string.

Fixes #45.

cherukumilli commented 8 years ago

@palli

Should line 75 be:

paramString = (paramString || '').replace(/\+/g, ' ')

instead of

paramString = (paramString || '').replace(/\+/g, '%20')
palli commented 8 years ago

@cherukumilli both will work, but having %20 is more correct because the string is still supposed to be encoded until decodeUriComponent has been called.

palli commented 8 years ago

Ping (the friendly kind) ?

Nexus2k commented 8 years ago

Another Ping.

rictic commented 8 years ago

Looks good, just one comment. Sorry for the delay, I initially thought this was caught up in the #36 mess, but it looks unrelated, as it's in the query param encoder.

rictic commented 8 years ago

LGTM, thanks for the contribution!

palli commented 8 years ago

Thanks! Can this be cherry picked into a new version ?

rictic commented 8 years ago

Released as v0.8.7!