summaryrefslogtreecommitdiff
path: root/lib/url.js
diff options
context:
space:
mode:
authorJunshu Okamoto <o_askgulf@icloud.com>2016-11-30 22:21:00 -0600
committerRich Trott <rtrott@gmail.com>2016-12-24 21:06:23 -0800
commitc65d55f0878a42c5a9fe775ee190d6092c527661 (patch)
tree7ecfdc28f2b543084b5b1cc8739dd663fc207f4c /lib/url.js
parentc732bd1d932d3f37f8e93c18877c49787dd00bd1 (diff)
downloadandroid-node-v8-c65d55f0878a42c5a9fe775ee190d6092c527661.tar.gz
android-node-v8-c65d55f0878a42c5a9fe775ee190d6092c527661.tar.bz2
android-node-v8-c65d55f0878a42c5a9fe775ee190d6092c527661.zip
url: do not truncate long hostnames
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: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'lib/url.js')
-rw-r--r--lib/url.js39
1 files changed, 14 insertions, 25 deletions
diff --git a/lib/url.js b/lib/url.js
index 0cc364686c..49f2a30726 100644
--- a/lib/url.js
+++ b/lib/url.js
@@ -408,33 +408,22 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
};
function validateHostname(self, rest, hostname) {
- for (var i = 0, lastPos; i <= hostname.length; ++i) {
- var code;
- if (i < hostname.length)
- code = hostname.charCodeAt(i);
- if (code === 46/*.*/ || i === hostname.length) {
- if (i - lastPos > 0) {
- if (i - lastPos > 63) {
- self.hostname = hostname.slice(0, lastPos + 63);
- return '/' + hostname.slice(lastPos + 63) + rest;
- }
- }
- lastPos = i + 1;
- continue;
- } else if ((code >= 48/*0*/ && code <= 57/*9*/) ||
- (code >= 97/*a*/ && code <= 122/*z*/) ||
- code === 45/*-*/ ||
- (code >= 65/*A*/ && code <= 90/*Z*/) ||
- code === 43/*+*/ ||
- code === 95/*_*/ ||
- code > 127) {
- continue;
- }
+ for (var i = 0; i < hostname.length; ++i) {
+ const code = hostname.charCodeAt(i);
+ const isValid = (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;
+
// Invalid host character
- self.hostname = hostname.slice(0, i);
- if (i < hostname.length)
+ if (!isValid) {
+ self.hostname = hostname.slice(0, i);
return '/' + hostname.slice(i) + rest;
- break;
+ }
}
}