| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f0dfe57 commit 5cb8b16
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,7 @@ const { | |||
| 26 | 26 | ObjectCreate, | |
| 27 | 27 | ObjectKeys, | |
| 28 | 28 | SafeSet, | |
| 29 | + StringPrototypeCharCodeAt, | ||
| 29 | 30 | } = primordials; | |
| 30 | 31 | ||
| 31 | 32 | const { toASCII } = require('internal/idna'); | |
@@ -156,6 +157,14 @@ function urlParse(url, parseQueryString, slashesDenoteHost) { | |||
| 156 | 157 | return urlObject; | |
| 157 | 158 | } | |
| 158 | 159 | ||
| 160 | + function isIpv6Hostname(hostname) { | ||
| 161 | + return ( | ||
| 162 | + StringPrototypeCharCodeAt(hostname, 0) === CHAR_LEFT_SQUARE_BRACKET && | ||
| 163 | + StringPrototypeCharCodeAt(hostname, hostname.length - 1) === | ||
| 164 | + CHAR_RIGHT_SQUARE_BRACKET | ||
| 165 | + ); | ||
| 166 | + } | ||
| 167 | + | ||
| 159 | 168 | Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { | |
| 160 | 169 | validateString(url, 'url'); | |
| 161 | 170 | ||
@@ -364,8 +373,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { | |||
| 364 | 373 | ||
| 365 | 374 | // If hostname begins with [ and ends with ] | |
| 366 | 375 | // assume that it's an IPv6 address. | |
| 367 | - const ipv6Hostname = hostname.charCodeAt(0) === CHAR_LEFT_SQUARE_BRACKET && | ||
| 368 | - hostname.charCodeAt(hostname.length - 1) === CHAR_RIGHT_SQUARE_BRACKET; | ||
| 376 | + const ipv6Hostname = isIpv6Hostname(hostname); | ||
| 369 | 377 | ||
| 370 | 378 | // validate a little. | |
| 371 | 379 | if (!ipv6Hostname) { | |
@@ -590,7 +598,7 @@ Url.prototype.format = function format() { | |||
| 590 | 598 | host = auth + this.host; | |
| 591 | 599 | } else if (this.hostname) { | |
| 592 | 600 | host = auth + ( | |
| 593 | - this.hostname.includes(':') ? | ||
| 601 | + this.hostname.includes(':') && !isIpv6Hostname(this.hostname) ? | ||
| 594 | 602 | '[' + this.hostname + ']' : | |
| 595 | 603 | this.hostname | |
| 596 | 604 | ); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -148,6 +148,12 @@ const formatTests = { | |||
| 148 | 148 | host: '[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:61616', | |
| 149 | 149 | pathname: '/s/stopButton' | |
| 150 | 150 | }, | |
| 151 | + 'http://[::]/': { | ||
| 152 | + href: 'http://[::]/', | ||
| 153 | + protocol: 'http:', | ||
| 154 | + hostname: '[::]', | ||
| 155 | + pathname: '/' | ||
| 156 | + }, | ||
| 151 | 157 | ||
| 152 | 158 | // Encode context-specific delimiters in path and query, but do not touch | |
| 153 | 159 | // other non-delimiter chars like `%`. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments