-
Notifications
You must be signed in to change notification settings - Fork 21
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
Does not decode plus signs #7
Comments
It can probably be fixed by replacing Line 24 in ca090ae
|
Technically, our implmentation is correct because the name of the parameter is indeed |
Or am I missing something obvious here. |
patch ready: diff --git a/index.js b/index.js
index e1a2684..0e9df10 100644
--- a/index.js
+++ b/index.js
@@ -3,6 +3,17 @@
var has = Object.prototype.hasOwnProperty;
/**
+ * Decode a URI encoded string.
+ *
+ * @param {String} input The URI encoded string.
+ * @returns {String} The decoded string.
+ * @api private
+ */
+function decode(input) {
+ return decodeURIComponent(input).replace(/\+/g, ' ');
+}
+
+/**
* Simple query string parser.
*
* @param {String} query The query string that needs to be parsed.
@@ -21,7 +32,7 @@ function querystring(query) {
//
for (;
part = parser.exec(query);
- result[decodeURIComponent(part[1])] = decodeURIComponent(part[2])
+ result[decode(part[1])] = decode(part[2])
);
return result;
diff --git a/test.js b/test.js
index 06d8cb2..754c9a5 100644
--- a/test.js
+++ b/test.js
@@ -33,7 +33,7 @@ describe('querystringify', function () {
it('works with object keys with empty string values', function () {
assume(qs.stringify({ foo: '' })).equals('foo=');
- })
+ });
it('works with nulled objects', function () {
var obj = Object.create(null);
@@ -70,6 +70,13 @@ describe('querystringify', function () {
assume(obj.foo).equals('');
assume(obj.bar).equals('');
assume(obj.shizzle).equals('mynizzle');
- })
+ });
+
+ it('decodes plus signs', function () {
+ var obj = qs.parse('foo+bar=baz+qux');
+
+ assume(obj).is.a('object');
+ assume(obj['foo bar']).equals('baz qux');
+ });
});
}); |
I see no reason to turn |
If we assume that our input is correctly encoded then yes it doesn't make sense.
|
I'm interested in fleshing this out all the way. You are correct that most parsers convert I can only see converting Pros of
Cons:
At this point, I can't form an opinion in favor either way. |
You are assuming that there are no more (modern) URL producers that encode with plus signs. At least Golang does: https://play.golang.org/p/g_TP0hegvE Python 3 does too:
As does PHP 7:
So there are many opportunities for querystringify to be confronted with such URLs. |
Wow. You're correct. I think my assumption was fair - I'm surprised that this is being practiced despite being contrary to the spec for the last 12 years! Why are they encoding spaces as |
Published as major 1.0.0 |
@3rd-Eden I can't see 1.0.0 on npm. Forgot to publish? |
Nah, publish failed because it went in to my private npm installation instead of public due to npmconfig missmatch. |
It's there now btw. |
Thanks all. @m59peacemaker, as far as I can see RFC 3986 does not disallow or even obsolete encoding space with plus. Presumably it is preferred over %20 for legibility. That is in fact why I noticed that querystringify didn't support it; status=open+assigned just looks nicer. |
I t does look nice. If you care to discuss a little further - I'm not sure you see the way I'm thinking about it (and it appears @3rd-Eden had the same thought). The best that I can understand it, 3986 says that the URI should be percent-encoded except the characters which have particular meaning to the scheme. There are characters which a scheme is allowed to use as delimiters to express whatever kind of thing it needs to. I discovered that application/x-www-form-urlencoded is the only scheme that uses Things get frustrating in my mind from there - what if there were new kinds of schemes and one said that |
This test fails:
The text was updated successfully, but these errors were encountered: