From b41a1954d05097b7e7efdf6433643780c87a9756 Mon Sep 17 00:00:00 2001 From: ATHULKNAIR Date: Wed, 17 May 2023 15:09:44 +0530 Subject: [PATCH] fix: data was binding to paths starting with same prefix --- src/medblocks/form/plugins/openEHRFlat.ts | 3 ++- test/mb-form.e2e.test.ts | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/medblocks/form/plugins/openEHRFlat.ts b/src/medblocks/form/plugins/openEHRFlat.ts index abafa0f..d527921 100644 --- a/src/medblocks/form/plugins/openEHRFlat.ts +++ b/src/medblocks/form/plugins/openEHRFlat.ts @@ -221,7 +221,8 @@ export const openEHRFlatPlugin: MbPlugin = { if (prefix && suffix) { elementsWithBasePath = Object.keys(parsedData).filter( path => - path.startsWith(prefix as string) && path.endsWith(suffix as string) + path.split(':')[0] === (prefix as string) && + path.endsWith(suffix as string) ); } else { elementsWithBasePath = Object.keys(parsedData).filter(path => diff --git a/test/mb-form.e2e.test.ts b/test/mb-form.e2e.test.ts index 6ce1004..84b2bc8 100644 --- a/test/mb-form.e2e.test.ts +++ b/test/mb-form.e2e.test.ts @@ -1248,4 +1248,22 @@ describe('Form e2e', () => { let data = await oneEvent(form, 'mb-submit'); expect(data.detail).to.eql({ input2: 'hello there' }); }); + + // if prefix of path starts with same prefix of another path, then data should not be added to both + it('path starts with similar prefix, should not bind data for other elements', async () => { + const form = await fixture(html` + + + + + `); + form.import({ 'test/path1:0/name': 'test value1' }); + await elementUpdated(form); + + expect(form.data).to.eql({ + 'test/path:0/name': [], + 'test/path1:0/name': ['test value1'], + }); + expect(form.export()).to.eql({ 'test/path1:0/name': 'test value1' }); + }); });