Uh oh!
There was an error while loading. Please reload this page.
url: refactor truncating long hostname - #9292
Conversation
There was a problem hiding this comment.
The moving-part-of-the-hostname-to-the-path bit is really surprising and, I would argue, buggy behavior. Is that documented anywhere? If not, I wonder if the correct thing to do is a (hopefully semver-patch) change that treats such URLs as invalid. (A hostname longer than 63 chars is invalid per RFC 1035.)
EDIT: It doesn't appear to be documented anywhere.
Trott
commented
Oct 26, 2016
/cc @nodejs/http-parser I guess, although I suppose this isn't |
jun-oka
commented
Oct 26, 2016
@Trott OK. I agree. I'll look into the document again. |
Trott
commented
Oct 26, 2016
Looks like this behavior was introduced (or at least refactored?) in db912813 by @mscdex. I'm not sure if it was unintentional and the intended behavior was something else, or if this is totally intended behavior on the theory that "garbage input results in garbage output". So maybe @mscdex can let us know? |
jasnell
commented
Oct 28, 2016
ping @mscdex |
mscdex
commented
Oct 28, 2016
I honestly don't remember, that was awhile ago. All I could go by is whatever tests we had at the time. |
Trott
commented
Oct 28, 2016
Looking at what I would say the path forward is:
What do others think? |
Trott
commented
Oct 28, 2016
I should add that, to me at least, the real objectionable thing here is not the truncation but the moving of the remainder of the hostname into the path. That just makes no sense to me. I cannot think of a situation where that is helpful. And I can think of situations where that can introduce bugs, for sure. |
jun-oka
commented
Nov 4, 2016
@Trott Thanks.
|
sam-github
commented
Nov 10, 2016
re: #9521 (comment), I think truncation is bizarre. I don't believe that the URL RFCs say that host names have to be _DNS_ host names, there are lots of ways of resolving names, so I think truncation is a bug. Here's an example: host names clearly are not the same as DNS names, they can be longer than DNS allows and still be resolveable. |
de9563d to
c186062CompareTrott
commented
Dec 1, 2016
Trott
commented
Dec 1, 2016
Trott
commented
Dec 1, 2016
/cc @sam-github |
jun-oka
commented
Dec 7, 2016
@cjihrig@jasnell@sam-github It would be nice if you can check it! |
sam-github
commented
Dec 7, 2016
There was a problem hiding this comment.
There is a backslash before z here that needs to be removed.
There was a problem hiding this comment.
OK. Thank you for finding.
There was a problem hiding this comment.
Please keep the parens around the groups of checks, IMHO it makes it easier to reason about.
@Trott I'm just being more cautious is all, especially since this behavior has existed for a long time (even before my rewrite). If everyone else feels differently, then go ahead and remove the semver-major label. |
jun-oka
commented
Dec 9, 2016
@mscdex |
c186062 to
1a0f8f5Comparejun-oka
commented
Dec 23, 2016
Trott
commented
Dec 24, 2016
There's a couple of changes that still need to be made, |
There was a problem hiding this comment.
While we're changing things in here, I think it might be better to re-prioritize the conditionals here to optimize for the common cases. Here is what I propose:
constisVc=(code>=97/*a*/&&code<=122/*z*/)||code===46/*.*/||(code>=65/*A*/&&code<=90/*Z*/)||(code>=48/*0*/&&code<=57/*9*/)||code===45/*-*/||code===43/*+*/||code===95/*_*/||code>127;There was a problem hiding this comment.
@mscdex In my opinion, that makes more sense. It looks more common in this case. Thanks a lot.
Currently, around line 417 lib/url.js is truncating hostname and put the rest of hostname to the path if hostname length after `.` is equal or more than 63. This behavior is different from browser behavior. I changed the code so that it doesn’t truncate. I also added the test example which has more than 63 length in after `.` in hostname in test url.
1a0f8f5 to
ac7c6beComparejun-oka
commented
Dec 24, 2016
@mscdex I have applied your review which you proposed. |
| (code >= 48/*0*/ && code <= 57/*9*/) || | ||
| code === 45/*-*/ || | ||
| code === 43/*+*/ || | ||
| code === 95/*_*/|| |
There was a problem hiding this comment.
minor nit: there is a missing space before the ||. I missed that in my proposed example earlier.
jun-oka
commented
Dec 24, 2016
@mscdex Thank you! I corrected it. I will be careful. |
Trott
commented
Dec 24, 2016
mscdex
commented
Dec 25, 2016
LGTM |
Trott
commented
Dec 25, 2016
(arm-fanned failure on CI is infra related and unrelated to this change.) |
Currently, around line 417 lib/url.js is truncating hostname and put the rest of hostname to the path if hostname length after `.` is equal or more than 63. This behavior is different from browser behavior. I changed the code so that it doesn’t truncate. I also added the test example which has more than 63 length in after `.` in hostname in test url. PR-URL: nodejs#9292 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
Trott
commented
Dec 25, 2016
Landed in c65d55f. Two months in the making. 🎉 |
Currently, around line 417 lib/url.js is truncating hostname and put the rest of hostname to the path if hostname length after `.` is equal or more than 63. This behavior is different from browser behavior. I changed the code so that it doesn’t truncate. I also added the test example which has more than 63 length in after `.` in hostname in test url. PR-URL: nodejs#9292 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
Checklist
make -j8 test(UNIX), orvcbuild test nosign(Windows) passesAffected core subsystem(s)
lib url
test url
Description of change
I deleted and refactored the line around 417 in url.js which was truncating hostname if hostname length after
.is more than 63. Thus url parse behavior for hostname should be same as browser's behavior. Now it doesn’t truncate hostname.