From 24aeb68ab48536387ce82294aaa206cd83cf5ae9 Mon Sep 17 00:00:00 2001 From: s9k Date: Mon, 11 Feb 2019 15:58:39 +0300 Subject: [PATCH] Fixed issue #55 undefined attribute values are converted to strings (#57) * Fixed issue #55 undefined attribute values are converted to strings * ignore attribute if injected value is null or undefined --- index.js | 1 + test/attr.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/index.js b/index.js index 209f3b6..2eed790 100644 --- a/index.js +++ b/index.js @@ -265,6 +265,7 @@ module.exports = function (h, opts) { if (typeof x === 'function') return x else if (typeof x === 'string') return x else if (x && typeof x === 'object') return x + else if (x === null || x === undefined) return x else return concat('', x) } } diff --git a/test/attr.js b/test/attr.js index 0cd3859..d4c94c7 100644 --- a/test/attr.js +++ b/test/attr.js @@ -74,3 +74,39 @@ test('strange inbetween character attributes', function (t) { t.equal(vdom.create(tree).toString(), `
`) t.end() }) + +test('null and undefined attributes', function (t) { + var tree = hx`
` + t.equal(vdom.create(tree).toString(), `
`) + t.end() +}) + +test('undefined (with quotes) attribute value is evaluated', function (t) { + var tree = hx`
` + t.equal(vdom.create(tree).toString(), `
`) + t.end() +}) + +test('null (with quotes) attribute value is evaluated', function (t) { + var tree = hx`
` + t.equal(vdom.create(tree).toString(), `
`) + t.end() +}) + +test('undefined (without quotes) attribute value is evaluated', function (t) { + var tree = hx`
` + t.equal(vdom.create(tree).toString(), `
`) + t.end() +}) + +test('null (without quotes) attribute value is evaluated', function (t) { + var tree = hx`
` + t.equal(vdom.create(tree).toString(), `
`) + t.end() +}) + +test('null is ignored and adjacent attribute is evaluated', function (t) { + var tree = hx`
` + t.equal(vdom.create(tree).toString(), `
`) + t.end() +})