Skip to content

Commit f6fc851

Browse files
committed
🎨 Replace URL.canParse with a try/catch block
fixes #244
1 parent bc1f570 commit f6fc851

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/addons/basicAuth.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ export interface BasicAuthAddon {
3333

3434
const makeBasicAuthMiddleware: (config: Config) => ConfiguredMiddleware = config => next => (url, opts) => {
3535
const _URL = config.polyfill("URL")
36-
const parsedUrl = _URL.canParse(url) ? new _URL(url) : null
36+
let parsedUrl: URL | null
37+
try {
38+
parsedUrl = new _URL(url)
39+
} catch {
40+
parsedUrl = null
41+
}
3742

3843
if (parsedUrl?.username || parsedUrl?.password) {
3944
const basicAuthBase64 = utf8ToBase64(

0 commit comments

Comments
 (0)