diff --git a/.travis.yml b/.travis.yml index 8524235..965fe2d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ language: node_js -node_js: - - 4 +node_js: node +cache: npm diff --git a/src/vhtml.js b/src/vhtml.js index 8576bc3..0e03f69 100644 --- a/src/vhtml.js +++ b/src/vhtml.js @@ -13,7 +13,7 @@ let sanitized = {}; /** Hyperscript reviver that constructs a sanitized HTML string. */ export default function h(name, attrs) { - let stack=[], s = `<${name}`; + let stack=[], s = ''; attrs = attrs || {}; for (let i=arguments.length; i-- > 2; ) { stack.push(arguments[i]); @@ -26,12 +26,15 @@ export default function h(name, attrs) { // return name(attrs, stack.reverse()); } - for (let i in attrs) { - if (attrs[i]!==false && attrs[i]!=null && i !== setInnerHTMLAttr) { - s += ` ${DOMAttributeNames[i] ? DOMAttributeNames[i] : esc(i)}="${esc(attrs[i])}"`; + if (name) { + s += '<' + name; + if (attrs) for (let i in attrs) { + if (attrs[i]!==false && attrs[i]!=null && i !== setInnerHTMLAttr) { + s += ` ${DOMAttributeNames[i] ? DOMAttributeNames[i] : esc(i)}="${esc(attrs[i])}"`; + } } + s += '>'; } - s += '>'; if (emptyTags.indexOf(name) === -1) { if (attrs[setInnerHTMLAttr]) { @@ -49,7 +52,7 @@ export default function h(name, attrs) { } } - s += `${name}>`; + s += name ? `${name}>` : ''; } sanitized[s] = true; diff --git a/test/vhtml.js b/test/vhtml.js index 8fef98e..f88ddf2 100644 --- a/test/vhtml.js +++ b/test/vhtml.js @@ -173,4 +173,21 @@ describe('vhtml', () => { '
' ); }); + + it('should support string fragments', () => { + expect( + h(null, null, "foo", "bar", "baz") + ).to.equal( + 'foobarbaz' + ); + }); + + it('should support element fragments', () => { + expect( + h(null, null,foo
, bar,foo
bar