Skip to content

Commit 4ae7ed2

Browse files
viceicerarkins
andauthored
fix(nuget): add simple check to skip non-xml files (renovatebot#37453)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
1 parent 3787141 commit 4ae7ed2

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

lib/modules/manager/nuget/extract.spec.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { DotnetVersionDatasource } from '../../datasource/dotnet-version';
66
import type { ExtractConfig } from '../types';
77
import { extractPackageFile } from '.';
88
import { Fixtures } from '~test/fixtures';
9-
import { fs } from '~test/util';
9+
import { fs, logger } from '~test/util';
1010

1111
const config: ExtractConfig = {};
1212

@@ -26,8 +26,34 @@ describe('modules/manager/nuget/extract', () => {
2626

2727
it('returns null for invalid csproj', async () => {
2828
expect(
29-
await extractPackageFile('nothing here', 'bogus', config),
29+
await extractPackageFile(
30+
'\uFEFF <?xml version="1.0" encoding="utf-8" ?>invalid xml>',
31+
'bogus',
32+
config,
33+
),
3034
).toBeNull();
35+
36+
expect(logger.logger.debug).toHaveBeenCalledWith(
37+
expect.anything(),
38+
'Failed to parse XML',
39+
);
40+
});
41+
42+
it('returns null if not xml', async () => {
43+
expect(
44+
await extractPackageFile(
45+
codeBlock`
46+
org.apache.curator:* =4.3.0
47+
org.apache.hadoop:*=3.1.4
48+
org.apache.hadoop.thirdparty:* = 1.1.0
49+
`,
50+
'versions.props',
51+
config,
52+
),
53+
).toBeNull();
54+
expect(logger.logger.debug).toHaveBeenCalledWith(
55+
'NuGet: Skipping versions.props as it is not XML',
56+
);
3157
});
3258

3359
it('extracts package version dependency', async () => {

lib/modules/manager/nuget/extract.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { XmlElement } from 'xmldoc';
33
import { XmlDocument } from 'xmldoc';
44
import { logger } from '../../../logger';
55
import { getSiblingFileName, localPathExists } from '../../../util/fs';
6+
import { regEx } from '../../../util/regex';
67
import { NugetDatasource } from '../../datasource/nuget';
78
import { getDep } from '../dockerfile/extract';
89
import type {
@@ -198,6 +199,13 @@ export async function extractPackageFile(
198199
return extractMsbuildGlobalManifest(content, packageFile, registries);
199200
}
200201

202+
// Simple xml validation.
203+
// Should start with `<` and end with `>` after trimming all whitespace
204+
if (!regEx(/^\s*<.+>$/m).test(content.trim())) {
205+
logger.debug(`NuGet: Skipping ${packageFile} as it is not XML`);
206+
return null;
207+
}
208+
201209
let deps: PackageDependency[] = [];
202210
let packageFileVersion: string | undefined;
203211
try {

0 commit comments

Comments
 (0)