Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.

Don't use regex to split query string since this doesn't work correctly in IE8 #567

Closed
wants to merge 1 commit into from

Conversation

martinbooth
Copy link
Contributor

this fixes #552

value = parts[1] && decodeURIComponent(parts[1].replace(/\+/g, ' '));
var sp = pair.indexOf("="),
key = sp === -1 ? pair : pair.substr(0, sp),
value = sp === -1 ? null : decodeURIComponent(pair.substr(sp + 1).replace(/\+/g, ' '));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a heads up, might not be a problem. This makes ?foo= be

foo: ''

and ?foo

foo: null

Before both of these became

foo: undefined

Could have some unwanted effects, not sure though. Depends how that data is handled further.

I used this in a local patch I made.

    var parts = pair.split('='),
      key = parts.shift(),
      rest = parts.join('=') || undefined
      value = rest && decodeURIComponent(rest.replace(/\+/g, ' '));

@PerLindenAddiva
Copy link

Ran into this myself. I appended a similar patch that is a bit more invasive but keeps the undefined values as before. See comments in
bf912a1#diff-0d9e763c6e75932eaad003c8584b0105

PerLindenAddiva referenced this pull request Sep 19, 2014
Currently if there are any '=' in the value of a param it will get
improperly split.

?token=1234==

Becomes

{ token: "1234" }

This fix should only split on the first instance. So the above example
should look like:

{ token: "1234==" }
@EisenbergEffect
Copy link
Member

Landed in branch Next-Version.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants