From 56d96e897eb0d8e3cfa92e7903dfbb1ba6c6cacb Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Thu, 15 Apr 2021 13:28:24 +0300 Subject: [PATCH] Improve key names validation for keys from user nuget config --- src/authutil.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/authutil.ts b/src/authutil.ts index 463f0d3..218166f 100644 --- a/src/authutil.ts +++ b/src/authutil.ts @@ -25,6 +25,12 @@ export function configAuthentication( writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig); } +function isValidKey( + key: string +): boolean { + return /^[0-9\w\-\_\.]+$/i.test(key); +} + function writeFeedToFile( feedUrl: string, existingFileLocation: string, @@ -109,9 +115,9 @@ function writeFeedToFile( xml = xml.ele('packageSourceCredentials'); sourceKeys.forEach(key => { - if (key.indexOf(' ') > -1) { + if (!isValidKey(key)) { throw new Error( - "This action currently can't handle source names with spaces. Remove the space from your repo's NuGet.config and try again." + "Source name can contain letters, numbers, and '-', '_', '.' symbols only, Please, fix source name in NuGet.config and try again." ); }