From fbc3ba8db27fd19ace2b99b1414d970f3c3bdde6 Mon Sep 17 00:00:00 2001 From: Sebastian Tiemann Date: Tue, 15 Oct 2024 12:01:43 +0200 Subject: [PATCH] feat(manager/maven): provide warning log if pom contains windows line ending (#31858) Co-authored-by: Sebastian Panse Co-authored-by: Rhys Arkins --- lib/modules/manager/maven/extract.spec.ts | 12 ++++++++++++ lib/modules/manager/maven/extract.ts | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/lib/modules/manager/maven/extract.spec.ts b/lib/modules/manager/maven/extract.spec.ts index d6689de4238d70..3efc9d99aea9fa 100644 --- a/lib/modules/manager/maven/extract.spec.ts +++ b/lib/modules/manager/maven/extract.spec.ts @@ -1,6 +1,7 @@ import { codeBlock } from 'common-tags'; import { Fixtures } from '../../../../test/fixtures'; import { fs } from '../../../../test/util'; +import { logger } from '../../../logger'; import { extractAllPackageFiles, extractExtensions, @@ -234,6 +235,17 @@ describe('modules/manager/maven/extract', () => { }); }); + it('extract dependencies with windows line endings', () => { + const logSpy = jest.spyOn(logger, 'warn'); + extractPackage( + ' \r\n', + 'some-file', + ); + expect(logSpy).toHaveBeenCalledWith( + 'Your pom.xml contains windows line endings. This is not supported and may result in parsing issues.', + ); + }); + it('tries minimum manifests', () => { const res = extractPackage(Fixtures.get('minimum.pom.xml'), 'some-file'); expect(res).toEqual({ diff --git a/lib/modules/manager/maven/extract.ts b/lib/modules/manager/maven/extract.ts index a46e485252dd27..ef06fe3911228c 100644 --- a/lib/modules/manager/maven/extract.ts +++ b/lib/modules/manager/maven/extract.ts @@ -26,6 +26,11 @@ function parsePom(raw: string, packageFile: string): XmlDocument | null { let project: XmlDocument; try { project = new XmlDocument(raw); + if (raw.includes('\r\n')) { + logger.warn( + 'Your pom.xml contains windows line endings. This is not supported and may result in parsing issues.', + ); + } } catch { logger.debug({ packageFile }, `Failed to parse as XML`); return null;