Skip to content

Commit

Permalink
fix: skip nonSimpleDomain when it is an IP (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Jun 14, 2024
1 parent 856e241 commit b46ceb2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ function parse (uri, opts) {
fragment: undefined
}
const gotEncoding = uri.indexOf('%') !== -1
let isIP = false
if (options.reference === 'suffix') uri = (options.scheme ? options.scheme + ':' : '') + '//' + uri

const matches = uri.match(URI_PARSE)
Expand All @@ -225,9 +226,12 @@ function parse (uri, opts) {
if (parsed.host) {
const ipv4result = normalizeIPv4(parsed.host)
if (ipv4result.isIPV4 === false) {
parsed.host = normalizeIPv6(ipv4result.host, { isIPV4: false }).host.toLowerCase()
const ipv6result = normalizeIPv6(ipv4result.host, { isIPV4: false })
parsed.host = ipv6result.host.toLowerCase()
isIP = ipv6result.isIPV6
} else {
parsed.host = ipv4result.host
isIP = true
}
}
if (parsed.scheme === undefined && parsed.userinfo === undefined && parsed.host === undefined && parsed.port === undefined && !parsed.path && parsed.query === undefined) {
Expand All @@ -251,7 +255,7 @@ function parse (uri, opts) {
// check if scheme can't handle IRIs
if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
// if host component is a domain name
if (parsed.host && (options.domainHost || (schemeHandler && schemeHandler.domainHost)) && nonSimpleDomain(parsed.host)) {
if (parsed.host && (options.domainHost || (schemeHandler && schemeHandler.domainHost)) && isIP === false && nonSimpleDomain(parsed.host)) {
// convert Unicode IDN -> ASCII IDN
try {
parsed.host = URL.domainToASCII(parsed.host.toLowerCase())
Expand Down

0 comments on commit b46ceb2

Please sign in to comment.