Skip to content
Merged
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
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const REGEX_HTTP_PROTOCOL = /^https?:\/\//i

module.exports = url => {
try {
const { href, hostname, hash } = new URL(url)
if (!REGEX_HTTP_PROTOCOL.test(href)) return false
const { href, hostname, hash, username, password } = new URL(url)
if (!REGEX_HTTP_PROTOCOL.test(href) || username || password) return false
const isIPv6 = hostname.startsWith('[') && hostname.endsWith(']')
const isPunycode = punycodeRegex.test(hostname)
const hasTextFragment = hash.startsWith('#:~:text=')
Expand Down
4 changes: 4 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ const test = require('ava').default
'http://Http://xn--80a0aaa.xn--p1ai',
'http://Http://kikobeats.com',
'https://admin:admin@test-http-login.vercel.app',
'https://trusted.example@example.com/#:~:text=x',
'https://user:pass@example.com/#:~:text=Example',
'https://trusted.example@xn--80a0aaa.com/',
'http://user:pass@[::1]/',
'http:!!!\0',
'http://-kikobeats.com'
])
Expand Down