Skip to content

Commit 23fa2c1

Browse files
Improve key names validation from user' nuget config #187
Improve key names validation from user' nuget config
2 parents 20e6808 + cde58ab commit 23fa2c1

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

dist/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4847,6 +4847,9 @@ function configAuthentication(feedUrl, existingFileLocation = '', processRoot =
48474847
writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig);
48484848
}
48494849
exports.configAuthentication = configAuthentication;
4850+
function isValidKey(key) {
4851+
return /^[\w\-\.]+$/i.test(key);
4852+
}
48504853
function getExistingNugetConfig(processRoot) {
48514854
const defaultConfigName = 'nuget.config';
48524855
const configFileNames = fs
@@ -4922,8 +4925,8 @@ function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) {
49224925
}
49234926
xml = xml.ele('packageSourceCredentials');
49244927
sourceKeys.forEach(key => {
4925-
if (key.indexOf(' ') > -1) {
4926-
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.");
4928+
if (!isValidKey(key)) {
4929+
throw new Error("Source name can contain letters, numbers, and '-', '_', '.' symbols only. Please, fix source name in NuGet.config and try again.");
49274930
}
49284931
xml = xml
49294932
.ele(key)

src/authutil.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export function configAuthentication(
2727
writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig);
2828
}
2929

30+
function isValidKey(key: string): boolean {
31+
return /^[\w\-\.]+$/i.test(key);
32+
}
33+
3034
function getExistingNugetConfig(processRoot: string) {
3135
const defaultConfigName = 'nuget.config';
3236
const configFileNames = fs
@@ -122,9 +126,9 @@ function writeFeedToFile(
122126
xml = xml.ele('packageSourceCredentials');
123127

124128
sourceKeys.forEach(key => {
125-
if (key.indexOf(' ') > -1) {
129+
if (!isValidKey(key)) {
126130
throw new Error(
127-
"This action currently can't handle source names with spaces. Remove the space from your repo's NuGet.config and try again."
131+
"Source name can contain letters, numbers, and '-', '_', '.' symbols only. Please, fix source name in NuGet.config and try again."
128132
);
129133
}
130134

0 commit comments

Comments
 (0)