From f6fc8513558e55d3c5349c6b6c625d42e99b4476 Mon Sep 17 00:00:00 2001 From: Julien Elbaz Date: Fri, 6 Sep 2024 23:00:43 +0200 Subject: [PATCH] :art: Replace URL.canParse with a try/catch block fixes #244 --- src/addons/basicAuth.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/addons/basicAuth.ts b/src/addons/basicAuth.ts index b16644f..1fdbf38 100644 --- a/src/addons/basicAuth.ts +++ b/src/addons/basicAuth.ts @@ -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(