Skip to content
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

fix: skip nonSimpleDomain when it is an IP #87

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,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 @@ -226,9 +227,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 @@ -252,7 +256,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
Loading