Skip to content

Commit

Permalink
Fix URI encoding (#1539)
Browse files Browse the repository at this point in the history
According to HTTP spec keys should be encoded slightly differently to
values.
  • Loading branch information
johnf authored Feb 17, 2020
1 parent 40424e6 commit c7a10e2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function serialize(obj) {
function pushEncodedKeyValuePair(pairs, key, val) {
if (val === undefined) return;
if (val === null) {
pairs.push(encodeURIComponent(key));
pairs.push(encodeURI(key));
return;
}

Expand All @@ -142,7 +142,7 @@ function pushEncodedKeyValuePair(pairs, key, val) {
pushEncodedKeyValuePair(pairs, `${key}[${subkey}]`, val[subkey]);
}
} else {
pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
pairs.push(encodeURI(key) + '=' + encodeURIComponent(val));
}
}

Expand Down
1 change: 1 addition & 0 deletions test/client/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('request.serializeObject()', () => {
serialize({ name: '&tj&' }, 'name=%26tj%26');
serialize({ '&name&': 'tj' }, '%26name%26=tj');
serialize({ hello: '`test`' }, 'hello=%60test%60');
serialize({ $hello: 'test' }, '$hello=test');
});
});

Expand Down

0 comments on commit c7a10e2

Please sign in to comment.