Skip to content

Commit

Permalink
fix(manager/nuget): support package sources with whitespaces in keys (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
olegkrivtsov committed Dec 8, 2021
1 parent 3f586ef commit 3a5ad66
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/manager/nuget/__fixtures__/with-whitespaces/NuGet.config
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="My Package Source" value="https://my.myget.org/F/my/auth/guid/api/v3/index.json" />
</packageSources>
</configuration>
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion 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';
Expand Down Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions lib/manager/nuget/extract.spec.ts
Expand Up @@ -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';
Expand Down

0 comments on commit 3a5ad66

Please sign in to comment.