From 44288f3b4a47ffd3d560eae99827f3c25c6e430b Mon Sep 17 00:00:00 2001 From: Andreas Pizsa Date: Thu, 17 Mar 2022 18:08:55 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20return=20empty=20string=20for=20empty=20?= =?UTF-8?q?attributes=20(=E2=80=9C=E2=80=9D,=20=E2=80=98=E2=80=99)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andreas Pizsa --- hypertag.js | 6 +++++- test/test.js | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/hypertag.js b/hypertag.js index 6b2bfe9..6b2b408 100644 --- a/hypertag.js +++ b/hypertag.js @@ -40,7 +40,11 @@ function parseAttrs(htmlTagText, tagKey = '<') { while ((match = matchPattern.exec(htmlTagText)) !== null) { const key = match[1] attrs[key] - = (match[5] !== null && match[5]) || (match[3] !== null && match[3]) || true + = match[5] !== undefined + ? match[5] + : (match[3] !== undefined + ? match[3] + : true) } return attrs } diff --git a/test/test.js b/test/test.js index 49f7fd9..1287b6b 100644 --- a/test/test.js +++ b/test/test.js @@ -65,6 +65,9 @@ test('attributes', t => { <${randomTagName} ${randomAttr}= "${randomValue}"> <${randomTagName} ${randomAttr} ='${randomValue}'> <${randomTagName} ${randomAttr} = ${randomValue}> + <${randomTagName} emptyTag = ""> + <${randomTagName} emptyTag = ''> + <${randomTagName} emptyTag = > <${randomTagName} ${randomAttr} = ${randomValue}> <${randomTagName} ${randomAttr} @@ -77,6 +80,9 @@ test('attributes', t => { {[tagKey]: randomTagName, [randomAttr]: randomValue}, {[tagKey]: randomTagName, [randomAttr]: randomValue}, {[tagKey]: randomTagName, [randomAttr]: randomValue}, + {[tagKey]: randomTagName, emptyTag: ''}, + {[tagKey]: randomTagName, emptyTag: ''}, + {[tagKey]: randomTagName, emptyTag: true}, {[tagKey]: randomTagName, [randomAttr]: randomValue}, {[tagKey]: randomTagName, [randomAttr]: randomValue} ])