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} ])