fix(approval): BPMN 流程图净化中文 id,修 bpmn-js「no diagram to display」
UI 走查实证:迁移的 BPMN 常用中文做 process/diagram id(如「招投标工程评审流程」), bpmn-js/moddle 的 NCName 校验拒非 ASCII id → 整图不渲染(illegal ID)。 ProcessDiagramController.sanitizeBpmnIds 把非法(非 ASCII NCName)id 及其所有引用 (id/bpmnElement/sourceRef/targetRef/...)一致重写为安全 ASCII id(稳定哈希), 只动 id/引用类属性、不碰 name(保中文节点名),并同步重映射当前/历史节点 id。 单测 ProcessDiagramControllerTest 4 绿;浏览器 live:25 形状渲染+当前节点绿高亮+中文标签正常。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -117,4 +117,37 @@ class ProcessDiagramControllerTest {
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.found").value(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sanitizeBpmnIds_中文id重写为安全ascii并同步引用与节点() {
|
||||
// 迁移 BPMN 用中文 process id + 中文 diagram id,bpmn-js 拒非 ASCII NCName。重写后引用须一致,name 不动。
|
||||
String xml = "<definitions>"
|
||||
+ "<process id=\"招投标流程\" name=\"招投标流程\">"
|
||||
+ "<userTask id=\"sid-A\"/>"
|
||||
+ "<sequenceFlow id=\"f1\" sourceRef=\"招投标流程\" targetRef=\"sid-A\"/>"
|
||||
+ "</process>"
|
||||
+ "<bpmndi:BPMNDiagram id=\"BPMNDiagram_招投标流程\">"
|
||||
+ "<bpmndi:BPMNPlane bpmnElement=\"招投标流程\"/>"
|
||||
+ "</bpmndi:BPMNDiagram></definitions>";
|
||||
List<String> active = new java.util.ArrayList<>(List.of("sid-A"));
|
||||
List<String> finished = new java.util.ArrayList<>(List.of("招投标流程"));
|
||||
|
||||
String out = ProcessDiagramController.sanitizeBpmnIds(xml, active, finished);
|
||||
|
||||
// 中文 id 不再出现在 id/ref 属性里,但 name 保留中文
|
||||
org.junit.jupiter.api.Assertions.assertFalse(out.contains("id=\"招投标流程\""));
|
||||
org.junit.jupiter.api.Assertions.assertFalse(out.contains("bpmnElement=\"招投标流程\""));
|
||||
org.junit.jupiter.api.Assertions.assertFalse(out.contains("sourceRef=\"招投标流程\""));
|
||||
org.junit.jupiter.api.Assertions.assertTrue(out.contains("name=\"招投标流程\"")); // 展示名不动
|
||||
org.junit.jupiter.api.Assertions.assertTrue(out.contains("id=\"sid-A\"")); // 合法 id 不动
|
||||
// 同一中文 id 的所有引用映射到同一安全 id(process id 与 sourceRef/bpmnElement 一致)
|
||||
java.util.regex.Matcher m = java.util.regex.Pattern.compile("<process id=\"(n[0-9a-f]+)\"").matcher(out);
|
||||
org.junit.jupiter.api.Assertions.assertTrue(m.find());
|
||||
String safe = m.group(1);
|
||||
org.junit.jupiter.api.Assertions.assertTrue(out.contains("sourceRef=\"" + safe + "\""));
|
||||
org.junit.jupiter.api.Assertions.assertTrue(out.contains("bpmnElement=\"" + safe + "\""));
|
||||
// 历史节点 id 同步重映射,当前节点 sid-A 不变
|
||||
org.junit.jupiter.api.Assertions.assertEquals(safe, finished.get(0));
|
||||
org.junit.jupiter.api.Assertions.assertEquals("sid-A", active.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user