Bug: wixLocation.query incorrectly parsing %20 as +

Hi there,

I am using wixLocation.query to obtain query items from the URL:
/?item1=value&item2=S ome%20value%20that%20has%20spaces

When I call wixLocation.query, I see that query.item2 actually equals ‘Some+value+that+has+spaces’ not ‘Some value that has spaces’

Regards,
Attakorn S.

1 Like

That’s not necessarily wrong at all and since they’ve made this choice they can’t really go back on it. You should be able to safely replace + with literal space because actual pluses will themselves be encoded to (I think) %2B.

https://stackoverflow.com/questions/2678551/when-to-encode-space-to-plus-or-20

Hi Lee, thanks for your reply. I understand the argument about encoding spaces to + but this is decoding. %20 should always get converted to literal space, not plus sign, especially this has nothing to do with application/x-www-form-urlencoded. I can’t replace + with literal space either because if I for example the user WANTS the string ‘Some+value’, this will be enconded to item2=S ome%2Bvalue, and wixLocation.query.item2 will be ‘Some+value’. Now if I turn + into literal space, I will get ‘Some value’ instead of ‘Some+value’.

Ah you’re right. It has unencoded everything else already. I also noticed while briefly testing that sometimes you do get literal space, though I couldn’t readily understand when/why.

Yeah you’re right, sometimes it does decode %20 correctly to literal space but most of the time it doesn’t…very weird!