Skip to content

Commit

Permalink
fix parsing of port
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners committed Jul 12, 2024
1 parent 0655453 commit fd8aa7d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ function parse (uri, opts) {

// fix port number
if (isNaN(parsed.port)) {
parsed.port = matches[5]
if (matches[5] === undefined) {
parsed.port = parsed.scheme === 'http' ? 80 : 443
} else {
parsed.port = matches[5]
}
}
if (parsed.host) {
const ipv4result = normalizeIPv4(parsed.host)
Expand Down
6 changes: 6 additions & 0 deletions test/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,5 +314,11 @@ test('URI parse', (t) => {

components = URI.parse('urn:foo:|\\24fpl')
t.equal(components.error, 'URN can not be parsed.')

components = URI.parse('http://example.com/')
t.equal(components.port, 80)
components = URI.parse('https://example.com/')
t.equal(components.port, 443)

t.end()
})

0 comments on commit fd8aa7d

Please sign in to comment.