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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove ampersand #23
Remove ampersand #23
Conversation
That's a invalid query string. The ampersand |
@@ -11,6 +11,10 @@ exports.parse = function (str) { | |||
return {}; | |||
} | |||
|
|||
if (str[0] == '&') { | |||
str = str.substr(1, str.length); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should implemented on line 8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saromanov ⬆️
This is remove only from start of the string. Not from all of this. For example: console.log(query.parse("&data=foo&data=bar&fun=bag)); //{ data: [ 'foo', 'bar' ], fun: 'bag' } |
No, I mean, why does your querystring start with a |
Yes, i know that this is invalid, but my main motivation was replace incorrect behavior(in my point of view) with ampersand. In other cases, even if you put something incorrect, your response will be also invalid console.log(query.parse("/data=foo")); //{ '/data': 'foo' }
console.log(query.parse("*data=foo")); //{ '*data': 'foo' } No problems. But with the ampersand case, you'll get: console.log(query.parse("&data=foo")); //{ '': null, data: 'foo' } And i decided to make "clear" response {data: 'foo'} without {'': null}. |
Alright, I guess it wouldn't hurt. Just fix the inline comments and I'll merge. |
Fixed! |
@@ -5,6 +5,10 @@ exports.parse = function (str) { | |||
return {}; | |||
} | |||
|
|||
if (str[0] == '&') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
triple equal
Thanks, @arthurvr! Fixed, again. |
@sindresorhus , sorry, i not have much experience with github pull requests and i don't know what to do next. I was fixed with your comments(move to the right lines), but should i open new pull request? Or commit it again? |
Sorry if I weren't clear. The |
Now, its clear for me :) |
Looks good. Thanks :) |
index.js
Outdated
} | ||
|
||
str = str.trim().replace(/^(\?|#)/, ''); | ||
str = str.trim().replace(/^(\?|#|&)/, ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is simpler and faster to use a regex /^[?#&]/
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt it has any practical performance difference, but it is indeed simpler. Thanks :)
Hi!
If query string starts with &, result from parse will be { '': null, data: 'item' }
So, I've just a made more predictable behavior.