Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fixed] Path.withQuery strips query if query is empty #599

Merged
merged 1 commit into from Jan 16, 2015

Conversation

mhils
Copy link
Contributor

@mhils mhils commented Dec 12, 2014

Hi there,

Path.withQuery did not strip off the query once it became empty. Here's a fix + test. 馃槂

Cheers,
Max

@ryanflorence
Copy link
Member

so would you never want foo/bar/?a?

@mhils
Copy link
Contributor Author

mhils commented Dec 15, 2014

Maybe if I pass "" instead of undefined, but I feel there should be some way to remove the element from the string.

Whatsoever, that's a different (and maybe opinionated) question. The current behaviour just isn't consistent:

> Path.withQuery('/a/b/c?foo=42&bar=43', { bar: undefined })
'/a/b/c?foo=42'

> Path.withQuery('/a/b/c?foo=42', { foo: undefined })
'/a/b/c?foo=42'

This fix treats the last remaining parameter similar to all others.

Cheers,
Max

@mjackson
Copy link
Member

Thanks @mhils !

mjackson added a commit that referenced this pull request Jan 16, 2015
[fixed] Path.withQuery strips query if query is empty
@mjackson mjackson merged commit 32478b3 into remix-run:master Jan 16, 2015
@mjackson
Copy link
Member

@mhils Your test failed. If you'd like I'd be happy to accept a PR where the test passes. Thanks!

@mhils
Copy link
Contributor Author

mhils commented Jan 17, 2015

@mjackson, tests work fine for me. Seems like travis is having an issue?
https://travis-ci.org/rackt/react-router/builds/43891839
I can't restart the test as it's not my repo.

Cheers,
Max

@mhils
Copy link
Contributor Author

mhils commented Jan 17, 2015

Ok, looks like there's a bug in the latest version of qs. I now get an error after updating.

> merge({a:'b'}, {a:undefined})
{ a: 'b' }

@mjackson
Copy link
Member

@mhils Ah, that's the cause. This definitely seems like something that should be changed upstream in qs. If they won't fix it we may decide to work around it here.

@mhils
Copy link
Contributor Author

mhils commented Jan 18, 2015

For the record, the patch here needs to be applied anyway. When I fixed this, qs worked as expected. Now, this first needs to be fixed in qs before it can be fixed in react-router... (In other words; why didn't you merge it right away when qs was still working? :D)

@mhils
Copy link
Contributor Author

mhils commented Jan 20, 2015

@nlf indicated in ljharb/qs#67 that this is not intended usage at all for the merge function. What's your take on this? I can adjust this patch to use object-assign (or something similar) if that would fit for you.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants