diff --git a/src/vhtml.js b/src/vhtml.js index 0e03f69..837e924 100644 --- a/src/vhtml.js +++ b/src/vhtml.js @@ -9,7 +9,7 @@ let DOMAttributeNames = { htmlFor: 'for' }; -let sanitized = {}; +let sanitized = new WeakMap(); /** Hyperscript reviver that constructs a sanitized HTML string. */ export default function h(name, attrs) { @@ -47,7 +47,7 @@ export default function h(name, attrs) { for (let i=child.length; i--; ) stack.push(child[i]); } else { - s += sanitized[child]===true ? child : esc(child); + s += sanitized.has(child) ? child : esc(child); } } } @@ -55,6 +55,7 @@ export default function h(name, attrs) { s += name ? `${name}>` : ''; } - sanitized[s] = true; - return s; + let res = new String(s); + sanitized.set(res, true); + return res; } diff --git a/test/vhtml.js b/test/vhtml.js index f88ddf2..83d8706 100644 --- a/test/vhtml.js +++ b/test/vhtml.js @@ -3,10 +3,14 @@ import { expect } from 'chai'; /** @jsx h */ /*global describe,it*/ +function valueOf(str) { + return str.valueOf(); +} + describe('vhtml', () => { it('should stringify html', () => { let items = ['one', 'two', 'three']; - expect( + expect(valueOf(
Here is a list of {items.length} items:
@@ -16,46 +20,46 @@ describe('vhtml', () => { )) }Here is a list of 3 items:
foo
, bar,foo
bar