Improve key names validation for keys from user nuget config

This commit is contained in:
Vladimir Safonkin 2021-04-15 13:28:24 +03:00
parent 5a201f5e82
commit 56d96e897e
1 changed files with 8 additions and 2 deletions

View File

@ -25,6 +25,12 @@ export function configAuthentication(
writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig); writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig);
} }
function isValidKey(
key: string
): boolean {
return /^[0-9\w\-\_\.]+$/i.test(key);
}
function writeFeedToFile( function writeFeedToFile(
feedUrl: string, feedUrl: string,
existingFileLocation: string, existingFileLocation: string,
@ -109,9 +115,9 @@ function writeFeedToFile(
xml = xml.ele('packageSourceCredentials'); xml = xml.ele('packageSourceCredentials');
sourceKeys.forEach(key => { sourceKeys.forEach(key => {
if (key.indexOf(' ') > -1) { if (!isValidKey(key)) {
throw new Error( 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."
); );
} }