Skip to content

Commit

Permalink
🎨 Replace URL.canParse with a try/catch block
Browse files Browse the repository at this point in the history
fixes #244
  • Loading branch information
elbywan committed Sep 6, 2024
1 parent bc1f570 commit f6fc851
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/addons/basicAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ export interface BasicAuthAddon {

const makeBasicAuthMiddleware: (config: Config) => ConfiguredMiddleware = config => next => (url, opts) => {
const _URL = config.polyfill("URL")
const parsedUrl = _URL.canParse(url) ? new _URL(url) : null
let parsedUrl: URL | null
try {
parsedUrl = new _URL(url)
} catch {
parsedUrl = null
}

if (parsedUrl?.username || parsedUrl?.password) {
const basicAuthBase64 = utf8ToBase64(
Expand Down

0 comments on commit f6fc851

Please sign in to comment.