Skip to content
Snippets Groups Projects
Unverified Commit 6f0092f8 authored by Michael Kriese's avatar Michael Kriese Committed by GitHub
Browse files

fix(nuget): normalize paths (#7745)

parent af311a69
Branches
No related tags found
No related merge requests found
import { readFileSync } from 'fs'; import { readFileSync } from 'fs';
import path from 'path';
import * as upath from 'upath'; import * as upath from 'upath';
import { ExtractConfig } from '../common'; import { ExtractConfig } from '../common';
import { extractPackageFile } from './extract'; import { extractPackageFile } from './extract';
...@@ -9,7 +8,7 @@ describe('lib/manager/nuget/extract', () => { ...@@ -9,7 +8,7 @@ describe('lib/manager/nuget/extract', () => {
let config: ExtractConfig; let config: ExtractConfig;
beforeEach(() => { beforeEach(() => {
config = { config = {
localDir: path.resolve('lib/manager/nuget/__fixtures__'), localDir: upath.resolve('lib/manager/nuget/__fixtures__'),
}; };
}); });
it('returns empty for invalid csproj', async () => { it('returns empty for invalid csproj', async () => {
......
...@@ -25,12 +25,17 @@ export async function determineRegistries( ...@@ -25,12 +25,17 @@ export async function determineRegistries(
): Promise<Registry[] | undefined> { ): Promise<Registry[] | undefined> {
// Valid file names taken from https://github.com/NuGet/NuGet.Client/blob/f64621487c0b454eda4b98af853bf4a528bef72a/src/NuGet.Core/NuGet.Configuration/Settings/Settings.cs#L34 // Valid file names taken from https://github.com/NuGet/NuGet.Client/blob/f64621487c0b454eda4b98af853bf4a528bef72a/src/NuGet.Core/NuGet.Configuration/Settings/Settings.cs#L34
const nuGetConfigFileNames = ['nuget.config', 'NuGet.config', 'NuGet.Config']; const nuGetConfigFileNames = ['nuget.config', 'NuGet.config', 'NuGet.Config'];
// normalize paths, otherwise startsWith can fail because of path delimitter mismatch
const baseDir = upath.normalizeSafe(localDir);
const nuGetConfigPath = await findUp(nuGetConfigFileNames, { const nuGetConfigPath = await findUp(nuGetConfigFileNames, {
cwd: upath.dirname(upath.join(localDir, packageFile)), cwd: upath.dirname(upath.join(baseDir, packageFile)),
type: 'file', type: 'file',
}); });
if (nuGetConfigPath?.startsWith(localDir) !== true) { if (
!nuGetConfigPath ||
upath.normalizeSafe(nuGetConfigPath).startsWith(baseDir) !== true
) {
return undefined; return undefined;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment