diff --git a/lib/modules/datasource/pypi/index.spec.ts b/lib/modules/datasource/pypi/index.spec.ts index a1c9407d09b9ab..2277797208af88 100644 --- a/lib/modules/datasource/pypi/index.spec.ts +++ b/lib/modules/datasource/pypi/index.spec.ts @@ -732,6 +732,18 @@ describe('modules/datasource/pypi/index', () => { expect(googleAuth).toHaveBeenCalledTimes(1); }); + it('ignores an invalid URL when checking for auth headers', async () => { + const config = { + registryUrls: ['not-a-url/simple/'], + }; + const res = await getPkgReleases({ + ...config, + datasource, + packageName: 'azure-cli-monitor', + }); + expect(res?.releases.pop()).toBeNil(); + }); + it('uses https://pypi.org/pypi/ instead of https://pypi.org/simple/', async () => { httpMock.scope(baseUrl).get('/azure-cli-monitor/json').reply(200, res1); const config = { diff --git a/lib/modules/datasource/pypi/index.ts b/lib/modules/datasource/pypi/index.ts index b2614866656793..64a270dfa7a21e 100644 --- a/lib/modules/datasource/pypi/index.ts +++ b/lib/modules/datasource/pypi/index.ts @@ -89,7 +89,13 @@ export class PypiDatasource extends Datasource { private async getAuthHeaders( lookupUrl: string, ): Promise { - const url = new URL(lookupUrl); + let url: URL + try { + url = new URL(lookupUrl); + } catch (err) { + logger.once.debug({ lookupUrl, err }, 'Failed to parse URL'); + return {} + } if (url.hostname.endsWith(googleArtifactRegistryDomain)) { const auth = await getGoogleAuthToken(); if (auth) {