feat: 插件BPMNAdapter支持特殊字符串转义#2381
Conversation
|
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #2375 by adding proper XML escaping in the BPMNElementsAdapter serialization/deserialization utilities so BPMN shape names (and other text/attribute content) containing special characters can round-trip correctly.
Changes:
- Introduced a shared
escapeXmlhelper injson2xml.tsand applied it to attribute values and text node content. - Replaced
xml2json’sxml_escapeimplementation with the sharedescapeXml.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/extension/src/bpmn-elements-adapter/xml2json.ts | Reuses escapeXml for XML generation escaping logic in ObjTree. |
| packages/extension/src/bpmn-elements-adapter/json2xml.ts | Adds escapeXml, escapes attributes/text output, and adjusts falsy handling in XML serialization. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (name === '-json') return '' | ||
| if (obj !== 0 && obj !== false && !obj) { | ||
| return `${prefix}<${name} />` | ||
| } | ||
| if (name === '#text') { | ||
| return prefix + obj | ||
| return prefix + escapeXml(String(obj)) |
There was a problem hiding this comment.
toXml now returns a self-closing element for falsy values before handling special node names like #text/#cdata-section/#comment. If a node uses #text with an empty string (valid when an element has attributes but empty text), this will emit <#text />, which is not valid XML and changes semantics. Consider moving the falsy short-circuit below the #text/#cdata/#comment branches (or exclude names starting with # from the self-closing behavior).
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
|
@DymoneLewis I've opened a new pull request, #2383, to work on those changes. Once the pull request is ready, I'll request review from you. |
fix #2375