Skip to content

Commit fc47474

Browse files
authored
fix(menu/ImportIEDs) correct instantiated IED name to avoid illegal characters (openscd#1143)
* Replace illegal characters in IED template instantiation, closes openscd#1142
1 parent 2171569 commit fc47474

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/menu/ImportIEDs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030

3131
function uniqueTemplateIedName(doc: XMLDocument, ied: Element): string {
3232
const [manufacturer, type] = ['manufacturer', 'type'].map(attr =>
33-
ied.getAttribute(attr)
33+
ied.getAttribute(attr)?.replace(/[^A-Za-z0-9_]/g, '')
3434
);
3535
const nameCore =
3636
manufacturer || type

test/integration/editors/triggered/ImportIedsPlugin.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,30 @@ describe('ImportIedsPlugin', () => {
7878
.exist;
7979
});
8080

81+
it('renames TEMPLATE IED element if manufacturer/type has illegal characters', async () => {
82+
importDoc = await fetch('/test/testfiles/importieds/template.icd')
83+
.then(response => response.text())
84+
.then(str => new DOMParser().parseFromString(str, 'application/xml'));
85+
86+
const ied = importDoc.querySelector('IED')!;
87+
ied.setAttribute('manufacturer', 'Fancy-Vendy');
88+
ied.setAttribute('type', 'Z#Mega$Y');
89+
90+
element.importDoc = importDoc;
91+
await element.updateComplete;
92+
93+
element.prepareImport();
94+
await parent.updateComplete;
95+
96+
console.log(
97+
element.doc?.querySelector(':root > IED')?.getAttribute('name')
98+
);
99+
100+
expect(
101+
element.doc?.querySelector(':root > IED[name="FancyVendy_ZMegaY_001"]')
102+
).to.exist;
103+
});
104+
81105
it('allows multiple import of TEMPLATE IEDs', async () => {
82106
const templateIED1 = await fetch(
83107
'/test/testfiles/importieds/template.icd'

0 commit comments

Comments
 (0)