From 3aa2b13e4d6e03c6b948109728da107e844e673b Mon Sep 17 00:00:00 2001 From: Daniel Mulholland Date: Fri, 23 Jun 2023 07:54:34 +1200 Subject: [PATCH 1/4] fix(wizards/foundation): Escape limit regexes, closes #1271 --- src/wizards/foundation/limits.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wizards/foundation/limits.ts b/src/wizards/foundation/limits.ts index 8096b637a9..b7e66518c3 100644 --- a/src/wizards/foundation/limits.ts +++ b/src/wizards/foundation/limits.ts @@ -3,7 +3,7 @@ const nameStartChar = '|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|[\u2C00-\u2FEF]' + '|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD]'; const nameChar = - nameStartChar + '|[.0-9-]|\u00B7|[\u0300-\u036F]|[\u203F-\u2040]'; + nameStartChar + '|[.0-9\\-]|\u00B7|[\u0300-\u036F]|[\u203F-\u2040]'; const name = nameStartChar + '(' + nameChar + ')*'; const nmToken = '(' + nameChar + ')+'; @@ -17,7 +17,7 @@ export const patterns = { nmToken, names: name + '( ' + name + ')*', nmTokens: nmToken + '( ' + nmToken + ')*', - decimal: '[+-]?[0-9]+(([.][0-9]*)?|([.][0-9]+))', + decimal: '[+\\-]?[0-9]+(([.][0-9]*)?|([.][0-9]+))', unsigned: '[+]?[0-9]+(([.][0-9]*)?|([.][0-9]+))', alphanumericFirstUpperCase: '[A-Z][0-9,A-Z,a-z]*', asciName: '[A-Za-z][0-9,A-Z,a-z_]*', From 5b2c82a3cd19f76d8b6888a5ff2bd9c99d45aedc Mon Sep 17 00:00:00 2001 From: Daniel Mulholland Date: Fri, 23 Jun 2023 08:10:01 +1200 Subject: [PATCH 2/4] Update snapshots and ignore regex expressions in snapshot --- .../dotype-wizarding.test.snap.js | 10 ----- .../templates/dotype-wizarding.test.ts | 40 +++++++++++++++++-- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/test/integration/editors/templates/__snapshots__/dotype-wizarding.test.snap.js b/test/integration/editors/templates/__snapshots__/dotype-wizarding.test.snap.js index c87158ebc2..d05a9d4040 100644 --- a/test/integration/editors/templates/__snapshots__/dotype-wizarding.test.snap.js +++ b/test/integration/editors/templates/__snapshots__/dotype-wizarding.test.snap.js @@ -679,7 +679,6 @@ snapshots["DOType wizards defines a createDOTypeWizard looks like the latest sna label="id" maxlength="127" minlength="1" - pattern="([:_A-Za-z]|[À-Ö]|[Ø-ö]|[ø-˿]|[Ͱ-ͽ]|[Ϳ-῿]|[‌-‍]|[⁰-↏]|[Ⰰ-⿯]|[、-퟿]|[豈-﷏]|[ﷰ-�]|[.0-9-]|·|[̀-ͯ]|[‿-⁀])+" required="" > @@ -688,13 +687,11 @@ snapshots["DOType wizards defines a createDOTypeWizard looks like the latest sna helper="[scl.desc]" label="desc" nullable="" - pattern="([ -~]|[…]|[ -퟿]|[-�])*" > @@ -783,7 +780,6 @@ snapshots["DOType wizards defines a dOTypeWizard looks like the latest snapshot" label="id" maxlength="127" minlength="1" - pattern="([:_A-Za-z]|[À-Ö]|[Ø-ö]|[ø-˿]|[Ͱ-ͽ]|[Ϳ-῿]|[‌-‍]|[⁰-↏]|[Ⰰ-⿯]|[、-퟿]|[豈-﷏]|[ﷰ-�]|[.0-9-]|·|[̀-ͯ]|[‿-⁀])+" required="" > @@ -792,13 +788,11 @@ snapshots["DOType wizards defines a dOTypeWizard looks like the latest snapshot" helper="[scl.desc]" label="desc" nullable="" - pattern="([ -~]|[…]|[ -퟿]|[-�])*" > @@ -1068,7 +1062,6 @@ snapshots["DOType wizards defines a sDOWizard to edit an existing SDO looks like dialoginitialfocus="" helper="[scl.name]" label="name" - pattern="[a-z][0-9A-Za-z]*" required="" > > @@ -1078,7 +1071,6 @@ snapshots["DOType wizards defines a sDOWizard to edit an existing SDO looks like helper="[scl.desc]" label="desc" nullable="" - pattern="([ -~]|[…]|[ -퟿]|[-�])*" > > @@ -1266,7 +1257,6 @@ snapshots["DOType wizards defines a sDOWizard to create a new SDO element looks helper="[scl.desc]" label="desc" nullable="" - pattern="([ -~]|[…]|[ -퟿]|[-�])*" > { }); it('looks like the latest snapshot', async () => { - await expect(parent.wizardUI.dialog).to.equalSnapshot(); + // prettier does not support escaping in regexes of the /v flag + await expect(parent.wizardUI.dialog).dom.to.equalSnapshot({ + ignoreAttributes: [ + { + tags: ['wizard-textfield'], + attributes: ['pattern'], + }, + ], + }); }); it('allows to add empty DOTypes to the project', async () => { @@ -171,7 +179,15 @@ describe('DOType wizards', () => { }); it('looks like the latest snapshot', async () => { - await expect(parent.wizardUI.dialog).to.equalSnapshot(); + // prettier does not support escaping in regexes of the /v flag + await expect(parent.wizardUI.dialog).dom.to.equalSnapshot({ + ignoreAttributes: [ + { + tags: ['wizard-textfield'], + attributes: ['pattern'], + }, + ], + }); }); it('edits DOType attributes id', async () => { @@ -242,7 +258,15 @@ describe('DOType wizards', () => { }); it('looks like the latest snapshot', async () => { - await expect(parent.wizardUI.dialog).to.equalSnapshot(); + // prettier does not support escaping in regexes of the /v flag + await expect(parent.wizardUI.dialog).dom.to.equalSnapshot({ + ignoreAttributes: [ + { + tags: ['wizard-textfield'], + attributes: ['pattern'], + }, + ], + }); }); it('edits SDO attributes name', async () => { expect(doc.querySelector('DOType[id="Dummy.WYE"] > SDO[name="phsA"]')).to @@ -330,7 +354,15 @@ describe('DOType wizards', () => { }); it('looks like the latest snapshot', async () => { - await expect(parent.wizardUI.dialog).to.equalSnapshot(); + // prettier does not support escaping in regexes of the /v flag + await expect(parent.wizardUI.dialog).dom.to.equalSnapshot({ + ignoreAttributes: [ + { + tags: ['wizard-textfield'], + attributes: ['pattern'], + }, + ], + }); }); it('creates a new SDO element', async () => { expect( From d4336d73934b574f41e3488254d7e02ded52d5da Mon Sep 17 00:00:00 2001 From: Daniel Mulholland Date: Sun, 25 Jun 2023 10:48:54 +1200 Subject: [PATCH 3/4] Add pattern check --- .../templates/dotype-wizarding.test.ts | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/test/integration/editors/templates/dotype-wizarding.test.ts b/test/integration/editors/templates/dotype-wizarding.test.ts index 9094394135..b43463a3d1 100644 --- a/test/integration/editors/templates/dotype-wizarding.test.ts +++ b/test/integration/editors/templates/dotype-wizarding.test.ts @@ -11,6 +11,8 @@ import TemplatesPlugin from '../../../../src/editors/Templates.js'; import { WizardTextField } from '../../../../src/wizard-textfield.js'; import { ListItemBase } from '@material/mwc-list/mwc-list-item-base'; +import { patterns } from '../../../../src/wizards/foundation/limits.js'; + describe('DOType wizards', () => { if (customElements.get('templates-editor') === undefined) customElements.define('templates-editor', TemplatesPlugin); @@ -80,6 +82,32 @@ describe('DOType wizards', () => { }); }); + // work around, because the escapes get removed in snapshot by prettier + it('should have correct pattern', async () => { + expect( + parent.wizardUI.dialog!.querySelectorAll('wizard-textfield[pattern]')! + .length + ).to.equal(3); + + expect( + parent.wizardUI + .dialog!.querySelectorAll('wizard-textfield[pattern]')[0] + .getAttribute('pattern') + ).to.equal(patterns.nmToken); + + expect( + parent.wizardUI + .dialog!.querySelectorAll('wizard-textfield[pattern]')[1] + .getAttribute('pattern') + ).to.equal(patterns.normalizedString); + + expect( + parent.wizardUI + .dialog!.querySelectorAll('wizard-textfield[pattern]')[2] + .getAttribute('pattern') + ).to.equal(patterns.cdc); + }); + it('allows to add empty DOTypes to the project', async () => { expect(doc.querySelector('DOType[id="myGeneralDOType"]')).to.not.exist; idField.maybeValue = 'myGeneralDOType'; @@ -190,6 +218,32 @@ describe('DOType wizards', () => { }); }); + // work around, because the escapes get removed in snapshot by prettier + it('should have correct pattern', async () => { + expect( + parent.wizardUI.dialog!.querySelectorAll('wizard-textfield[pattern]')! + .length + ).to.equal(3); + + expect( + parent.wizardUI + .dialog!.querySelectorAll('wizard-textfield[pattern]')[0] + .getAttribute('pattern') + ).to.equal(patterns.nmToken); + + expect( + parent.wizardUI + .dialog!.querySelectorAll('wizard-textfield[pattern]')[1] + .getAttribute('pattern') + ).to.equal(patterns.normalizedString); + + expect( + parent.wizardUI + .dialog!.querySelectorAll('wizard-textfield[pattern]')[2] + .getAttribute('pattern') + ).to.equal(patterns.normalizedString); + }); + it('edits DOType attributes id', async () => { expect(doc.querySelector('DOType[id="Dummy.LLN0.Mod"]')).to.exist; idField.value = 'changedDOType'; @@ -268,6 +322,27 @@ describe('DOType wizards', () => { ], }); }); + + // work around, because the escapes get removed in snapshot by prettier + it('should have correct pattern', async () => { + expect( + parent.wizardUI.dialog!.querySelectorAll('wizard-textfield[pattern]')! + .length + ).to.equal(2); + + expect( + parent.wizardUI + .dialog!.querySelectorAll('wizard-textfield[pattern]')[0] + .getAttribute('pattern') + ).to.equal(patterns.tRestrName1stL); + + expect( + parent.wizardUI + .dialog!.querySelectorAll('wizard-textfield[pattern]')[1] + .getAttribute('pattern') + ).to.equal(patterns.normalizedString); + }); + it('edits SDO attributes name', async () => { expect(doc.querySelector('DOType[id="Dummy.WYE"] > SDO[name="phsA"]')).to .exist; @@ -364,6 +439,7 @@ describe('DOType wizards', () => { ], }); }); + it('creates a new SDO element', async () => { expect( doc.querySelector( @@ -381,6 +457,7 @@ describe('DOType wizards', () => { ) ).to.exist; }); + it('creates yet another new SDO element', async () => { const name = 'newSDOElement2'; const desc = 'newSDOdesc'; From bc0099da026d40f034eb0c756641eb3e4b9ea63c Mon Sep 17 00:00:00 2001 From: Daniel Mulholland Date: Mon, 26 Jun 2023 20:56:41 +1200 Subject: [PATCH 4/4] Add additional pattern check --- .../templates/dotype-wizarding.test.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/integration/editors/templates/dotype-wizarding.test.ts b/test/integration/editors/templates/dotype-wizarding.test.ts index b43463a3d1..7bdd43e34b 100644 --- a/test/integration/editors/templates/dotype-wizarding.test.ts +++ b/test/integration/editors/templates/dotype-wizarding.test.ts @@ -440,6 +440,26 @@ describe('DOType wizards', () => { }); }); + // work around, because the escapes get removed in snapshot by prettier + it('should have correct pattern', async () => { + expect( + parent.wizardUI.dialog!.querySelectorAll('wizard-textfield[pattern]')! + .length + ).to.equal(2); + + expect( + parent.wizardUI + .dialog!.querySelectorAll('wizard-textfield[pattern]')[0] + .getAttribute('pattern') + ).to.equal(patterns.tRestrName1stL); + + expect( + parent.wizardUI + .dialog!.querySelectorAll('wizard-textfield[pattern]')[1] + .getAttribute('pattern') + ).to.equal(patterns.normalizedString); + }); + it('creates a new SDO element', async () => { expect( doc.querySelector(