-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
url: spec-compliant URLSearchParams serializer #11626
Conversation
Awesome! Will take a look at it in detail tomorrow |
lib/internal/url.js
Outdated
// Ref: https://url.spec.whatwg.org/#concept-urlencoded-serializer | ||
function serializeParams(array) { | ||
const len = array.length; | ||
if (!len) |
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.
nit: len === 0
to avoid conversion to boolean
lib/internal/url.js
Outdated
return ''; | ||
|
||
var output = `${escapeParam(array[0])}=${escapeParam(array[1])}`; | ||
for (var i = 2; i < array.length; i += 2) |
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.
nit: use len
also here or do not create it earlier
@@ -154,7 +154,7 @@ test(function() { | |||
}, "Constructor with sequence of sequences of strings"); | |||
|
|||
[ | |||
// { "input": {"+": "%C2"}, "output": [[" ", "\uFFFD"]], "name": "object with +" }, | |||
{ "input": {"+": "%C2"}, "output": [["+", "%C2"]], "name": "object with +" }, |
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.
can you update the Refs SHA? This fix was in e94c604
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.
Great work! Feel good to see the tests get uncommented =)
lib/internal/url.js
Outdated
|
||
// ASCII | ||
if (c < 0x80) { | ||
if (noEscapeParam[c] === 1) |
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.
nit: Maybe noEscapeTable
? The name noEscapeParam
together with the function name escapeParam
looks a bit weird..
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.
Yeah... I agree. Used the more standard noEscape
instead.
lib/internal/url.js
Outdated
out += str.slice(lastPos, i); | ||
lastPos = i + 1; | ||
if (c === 0x20) | ||
out += '+'; |
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.
Another way would be to fork the hexTable
too with hexTable[0x20] = '+'
..not sure how much that would gain though.
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.
Nice, that does bring some speedup (consistently 1-2% for altspace
benchmark).
805fbcf
to
b05e5de
Compare
@targos, @joyeecheung, PR updated to address comments. |
Still LGTM |
@jasnell PTAL... |
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.
My apologies on the late review.. been a bit distracted. This LGTM so long as CI is green :-)
b05e5de
to
059e1fb
Compare
CI is actually passing. Landed in d77a758. Thanks all. |
PR-URL: nodejs#11626 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]>
@TimothyGu this is not landing in Question: do you have a list of all the URL commits that need backport? |
PR-URL: nodejs#11626 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]>
Differences with
querystring
module (which the serializer currently depends on):querystring
%20
+
'
'
%27
(
(
%28
)
)
%29
~
~
%7E
A C++ implementation cannot seem to reach the JS version's performance.
Benchmark: before vs. after
Benchmark: legacy (
querystring
) vs. WHATWGChecklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
url