From 9eb9758635bee8b1a30765818e46ee09e7741de5 Mon Sep 17 00:00:00 2001 From: Alexander Amosov Date: Fri, 6 Oct 2017 14:27:43 +0300 Subject: [PATCH 1/2] Fixed issue #55 undefined attribute values are converted to strings --- index.js | 1 + test/attr.js | 6 ++++++ 2 files changed, 7 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..21e9ae8 100644 --- a/test/attr.js +++ b/test/attr.js @@ -74,3 +74,9 @@ 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() +}) From 1028609990cad895f8b015600f13f47daf151abf Mon Sep 17 00:00:00 2001 From: jjurman Date: Mon, 11 Feb 2019 13:55:02 +0100 Subject: [PATCH 2/2] ignore attribute if injected value is null or undefined --- test/attr.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/attr.js b/test/attr.js index 21e9ae8..d4c94c7 100644 --- a/test/attr.js +++ b/test/attr.js @@ -80,3 +80,33 @@ test('null and undefined attributes', function (t) { 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() +})