diff --git a/lib/manager/nuget/__fixtures__/with-whitespaces/NuGet.config b/lib/manager/nuget/__fixtures__/with-whitespaces/NuGet.config
new file mode 100644
index 00000000000000..cc8abe128eb32c
--- /dev/null
+++ b/lib/manager/nuget/__fixtures__/with-whitespaces/NuGet.config
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/lib/manager/nuget/__fixtures__/with-whitespaces/with-whitespaces.csproj b/lib/manager/nuget/__fixtures__/with-whitespaces/with-whitespaces.csproj
new file mode 100644
index 00000000000000..872e2011797349
--- /dev/null
+++ b/lib/manager/nuget/__fixtures__/with-whitespaces/with-whitespaces.csproj
@@ -0,0 +1,12 @@
+
+
+
+ netcoreapp3.1
+ true
+
+
+
+
+
+
+
diff --git a/lib/manager/nuget/artifacts.ts b/lib/manager/nuget/artifacts.ts
index a3b6fdeaab8d33..3ff382af536705 100644
--- a/lib/manager/nuget/artifacts.ts
+++ b/lib/manager/nuget/artifacts.ts
@@ -1,4 +1,5 @@
import { join } from 'path';
+import { quote } from 'shlex';
import { GlobalConfig } from '../../config/global';
import { TEMPORARY_ERROR } from '../../constants/error-messages';
import { id, parseRegistryUrl } from '../../datasource/nuget';
@@ -45,7 +46,7 @@ async function addSourceCmds(
let addSourceCmd = `dotnet nuget add source ${registryInfo.feedUrl} --configfile ${nugetConfigFile}`;
if (registry.name) {
// Add name for registry, if known.
- addSourceCmd += ` --name ${registry.name}`;
+ addSourceCmd += ` --name ${quote(registry.name)}`;
}
if (username && password) {
// Add registry credentials from host rules, if configured.
diff --git a/lib/manager/nuget/extract.spec.ts b/lib/manager/nuget/extract.spec.ts
index e12e01825c8af8..d12fc9b4e69adb 100644
--- a/lib/manager/nuget/extract.spec.ts
+++ b/lib/manager/nuget/extract.spec.ts
@@ -132,6 +132,26 @@ describe('manager/nuget/extract', () => {
],
});
});
+
+ it('handles NuGet.config with whitespaces in package source keys', async () => {
+ const packageFile = 'with-whitespaces/with-whitespaces.csproj';
+ const contents = loadFixture(packageFile);
+ expect(await extractPackageFile(contents, packageFile, config)).toEqual({
+ deps: [
+ {
+ currentValue: '12.0.3',
+ datasource: 'nuget',
+ depName: 'Newtonsoft.Json',
+ depType: 'nuget',
+ registryUrls: [
+ 'https://api.nuget.org/v3/index.json#protocolVersion=3',
+ 'https://my.myget.org/F/my/auth/guid/api/v3/index.json',
+ ],
+ },
+ ],
+ });
+ });
+
it('ignores local feed in NuGet.config', async () => {
const packageFile =
'with-local-feed-in-config-file/with-local-feed-in-config-file.csproj';