mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 22:15:50 +00:00
fix(java): preserve Maven POM version spelling (#12714)
Co-authored-by: hhang <169027046+xu91102@users.noreply.github.com>
This commit is contained in:
1 parent
bb8e6833eb
commit
e1218b0388
3 files changed
+41
-6
No files matched your search
@@ -449,6 +449,31 @@ it("applies XML end-of-line handling to POM text", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[" ", "\u00a0"],
|
||||
["", "\ufeff"],
|
||||
[" ", ""],
|
||||
])(
|
||||
"preserves declared POM version characters at a %s boundary",
|
||||
(reference, retained) => {
|
||||
const report = parse(`<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>example</groupId>
|
||||
<artifactId>demo</artifactId>
|
||||
<version> ${reference}1.0${reference} </version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>example</groupId>
|
||||
<artifactId>library</artifactId>
|
||||
<version> ${reference}2.0${reference} </version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>`);
|
||||
expect(report.coordinates.version).toBe(`${retained}1.0${retained}`);
|
||||
expect(report.dependencies[0]?.version).toBe(`${retained}2.0${retained}`);
|
||||
},
|
||||
);
|
||||
|
||||
it("lists properties in packaging, scope, type and classifier", () => {
|
||||
const report = parse(`<project>
|
||||
<groupId>com.example</groupId>
|
||||
|
||||
@@ -97,8 +97,7 @@ const nonempty = (value: string | null | undefined): string | null => {
|
||||
return trimmed === "" ? null : trimmed;
|
||||
};
|
||||
|
||||
const elementText = (element: Element | undefined): string | null => {
|
||||
if (element === undefined) return null;
|
||||
const elementText = (element: Element): string => {
|
||||
const parts: string[] = [];
|
||||
for (
|
||||
let child = element.firstChild;
|
||||
@@ -108,11 +107,20 @@ const elementText = (element: Element | undefined): string | null => {
|
||||
// Text (3) and CDATA section (4) nodes both carry character data.
|
||||
if (child.nodeType === 3 || child.nodeType === 4)
|
||||
parts.push(child.nodeValue ?? "");
|
||||
return nonempty(parts.join(""));
|
||||
return parts.join("");
|
||||
};
|
||||
|
||||
const childText = (element: Element, local: string): string | null =>
|
||||
elementText(soleNamed(element, local));
|
||||
const childText = (element: Element, local: string): string | null => {
|
||||
const child = soleNamed(element, local);
|
||||
if (child === undefined) return null;
|
||||
const text = elementText(child);
|
||||
// Maven's model reader applies Java String.trim() to these fields.
|
||||
let start = 0;
|
||||
let end = text.length;
|
||||
while (start < end && text.charCodeAt(start) <= 0x20) start += 1;
|
||||
while (end > start && text.charCodeAt(end - 1) <= 0x20) end -= 1;
|
||||
return start === end ? null : text.slice(start, end);
|
||||
};
|
||||
|
||||
const textOf = (value: unknown): string | null =>
|
||||
typeof value === "string" ? nonempty(value) : null;
|
||||
@@ -346,7 +354,7 @@ const parsePom = (
|
||||
const {
|
||||
url: value,
|
||||
url_credentials_redacted: value_credentials_redacted,
|
||||
} = redactRecordedTransportUrl(elementText(property));
|
||||
} = redactRecordedTransportUrl(nonempty(elementText(property)));
|
||||
// Maven property keys are the written qualified names, not XML
|
||||
// expanded names: different prefixes remain different keys.
|
||||
return { name: property.tagName, value, value_credentials_redacted };
|
||||
|
||||
Reference in new issue
Block a user