This is an automated email from the ASF dual-hosted git repository.
tiagobento pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-tools.git
The following commit(s) were added to refs/heads/main by this push:
new 40f0bd1de65 kie-issues#2089: xml-parser-ts: idRandomizer should
correctly take into account text elements (#3267)
40f0bd1de65 is described below
commit 40f0bd1de65898452c6d1ba7af4dbdefe99fe3e4
Author: Luiz João Motta <[email protected]>
AuthorDate: Tue Sep 9 18:01:33 2025 -0300
kie-issues#2089: xml-parser-ts: idRandomizer should correctly take into
account text elements (#3267)
---
packages/xml-parser-ts/src/idRandomizer.ts | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/packages/xml-parser-ts/src/idRandomizer.ts
b/packages/xml-parser-ts/src/idRandomizer.ts
index 33b22daed4a..9ba9de92537 100644
--- a/packages/xml-parser-ts/src/idRandomizer.ts
+++ b/packages/xml-parser-ts/src/idRandomizer.ts
@@ -125,27 +125,35 @@ export class XmlParserTsIdRandomizer<M extends Meta> {
attr
)}: ${json})`
);
- return (parentJson[accessor] = newId);
+ // Differently from attributes, ID and IDREF *elements* store their
value in the `__$$text` property.
+ return (parentJson[accessor] = json?.__$$text ? { __$$text: newId }
: newId);
};
// Attributes an ID in case `json` === undefined
if (json === undefined) {
this.toAttribute.set(path === undefined ? String(attr) : path, u);
} else {
- this.updaters.set(json, [...(this.updaters.get(json) ?? []), u]);
+ // When it is an *element* instead of an attribute, correctly pass
the `__$$text` value
+ this.updaters.set(json.__$$text ? json.__$$text : json, [
+ ...(this.updaters.get(json.__$$text ? json.__$$text : json) ?? []),
+ u,
+ ]);
}
}
// QName
else if (rootMetaProp.xsdType === "xsd:QName") {
- const qname = parseXmlQName(json ?? "");
+ // Differently from attributes, QName *elements* store their value in
the `__$$text` property.
+ const qname = parseXmlQName((json?.__$$text ? json.__$$text : json) ??
"");
const u: XmlParserTsIdRandomizerUpdater = ({ newId }) => {
console.debug(
`ID RANDOMIZER: [QName] Updating id from ${qname.localPart} to
${newId} @ (${String(type)}.${String(
attr
)}: ${json})`
);
- return (parentJson[accessor] = buildXmlQName({ ...qname, localPart:
newId }));
+ return (parentJson[accessor] = json?.__$$text
+ ? { __$$text: buildXmlQName({ ...qname, localPart: newId }) }
+ : buildXmlQName({ ...qname, localPart: newId }));
};
this.updaters.set(qname.localPart,
[...(this.updaters.get(qname.localPart) ?? []), u]);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]