Skip to content

Commit

Permalink
Wrap new URL() in a try-catch
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunet committed Sep 7, 2024
1 parent e71b81a commit f2754db
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/modules/datasource/pypi/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
8 changes: 7 additions & 1 deletion lib/modules/datasource/pypi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ export class PypiDatasource extends Datasource {
private async getAuthHeaders(
lookupUrl: string,
): Promise<OutgoingHttpHeaders> {
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) {
Expand Down

0 comments on commit f2754db

Please sign in to comment.