Skip to content

Commit

Permalink
fix: return empty string for empty attributes (“”, ‘’)
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Pizsa <hopster@gmail.com>
  • Loading branch information
AndreasPizsa committed Mar 17, 2022
1 parent 53d8b8e commit 44288f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion hypertag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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}
])
Expand Down

0 comments on commit 44288f3

Please # to comment.