Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

const url = require('node:url')
const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4, nonSimpleDomain } = require('./lib/utils')
const { SCHEMES, getSchemeHandler } = require('./lib/schemes')

Expand Down Expand Up @@ -290,7 +291,7 @@ function parse (uri, opts) {
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())
parsed.host = url.domainToASCII(parsed.host.toLowerCase())
} catch (e) {
parsed.error = parsed.error || "Host's domain name can not be converted to ASCII: " + e
}
Expand Down
12 changes: 12 additions & 0 deletions test/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ test('URI parse', (t) => {
t.equal(components.query, undefined, 'query')
t.equal(components.fragment, undefined, 'fragment')

// non simple domain with schemeHandler
components = fastURI.parse('https://foo-bar-123.example.com')
t.equal(components.error, undefined, 'host errors')
t.equal(components.scheme, 'https', 'scheme')
// t.equal(components.authority, "", "authority");
t.equal(components.userinfo, undefined, 'userinfo')
t.equal(components.host, 'foo-bar-123.example.com', 'host non simple domain')
t.equal(components.port, undefined, 'port')
t.equal(components.path, '', 'path')
t.equal(components.query, undefined, 'query')
t.equal(components.fragment, undefined, 'fragment')

// port
components = fastURI.parse('//:')
t.equal(components.error, undefined, 'port errors')
Expand Down
Loading