From 8febb57c91b849b6e8da27476ad11266c9f6bb00 Mon Sep 17 00:00:00 2001 From: Natasha <67543397+NovemberTang@users.noreply.github.com> Date: Tue, 11 Jun 2024 10:15:09 +0100 Subject: [PATCH] Do not attempt to sort the URL if it is invalid --- packages/repocop/src/evaluation/repository.ts | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/repocop/src/evaluation/repository.ts b/packages/repocop/src/evaluation/repository.ts index de786a5f5..b8d98f388 100644 --- a/packages/repocop/src/evaluation/repository.ts +++ b/packages/repocop/src/evaluation/repository.ts @@ -402,20 +402,25 @@ export function evaluateOneRepo( //create a predicate that orders a list of urls by whether they contain snyk.io first, and then github.com second const urlSortPredicate = (url: string) => { - const parsedUrl = new URL(url); - - if ( - parsedUrl.hostname == 'snyk.io' || - parsedUrl.hostname == 'security.snyk.io' - ) { - return -2; - } else if ( - parsedUrl.hostname == 'github.com' && - parsedUrl.pathname.includes('advisories') - ) { - return -1; + try { + const parsedUrl = new URL(url); + + if ( + parsedUrl.hostname == 'snyk.io' || + parsedUrl.hostname == 'security.snyk.io' + ) { + return -2; + } else if ( + parsedUrl.hostname == 'github.com' && + parsedUrl.pathname.includes('advisories') + ) { + return -1; + } + return 0; + } catch { + //Do nothing if the url is invalid + return 0; } - return 0; }; export function dependabotAlertToRepocopVulnerability(