From 4a52a3767379f64d14c5e3bc0802bc425a2a7040 Mon Sep 17 00:00:00 2001 From: Christian Dinkel Date: Wed, 20 Jul 2022 10:57:10 +0200 Subject: [PATCH 1/2] fix(editing): set false attribute values on update Since we switched from Replace to Update, we now no longer set falsey attribute values (like the empty string `''` or `0`). This fixes that issue. --- src/Editing.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Editing.ts b/src/Editing.ts index 88611e5550..fa25f8be5e 100644 --- a/src/Editing.ts +++ b/src/Editing.ts @@ -382,7 +382,8 @@ export function Editing(Base: TBase) { ); Object.entries(action.newAttributes).forEach(([key, value]) => { - if (value) action.element.setAttribute(key, value); + if (value !== null && value !== undefined) + action.element.setAttribute(key, value); }); return true; From 49d4d295b12ddc862c02c6cf16d434528f7a6329 Mon Sep 17 00:00:00 2001 From: Jakob Vogelsang Date: Tue, 25 Oct 2022 20:18:34 +0200 Subject: [PATCH 2/2] test(Editing): add regression test --- test/unit/Editing.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/unit/Editing.test.ts b/test/unit/Editing.test.ts index 04413af5a8..ca49ffcc77 100644 --- a/test/unit/Editing.test.ts +++ b/test/unit/Editing.test.ts @@ -341,6 +341,19 @@ describe('EditingElement', () => { expect(element).to.not.have.attribute('desc'); }); + it('allows empty string as attribute value', () => { + const newAttributes: Record = {}; + newAttributes['name'] = ''; + + elm.dispatchEvent( + newActionEvent(createUpdateAction(element, newAttributes)) + ); + + expect(element.parentElement).to.equal(parent); + expect(element).to.have.attribute('name', ''); + expect(element).to.not.have.attribute('desc'); + }); + it('does not update an element in case of name conflict', () => { const newAttributes: Record = {}; newAttributes['name'] = 'Q02';