Skip to content

Commit

Permalink
Merge branch 'rbelouin-escape'
Browse files Browse the repository at this point in the history
  • Loading branch information
acstll committed Nov 20, 2017
2 parents a291733 + f9b868c commit 9ac022c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions init.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

var escape = require('lodash.escape')
var parseSelector = require('parse-sel')
var VOID_ELEMENTS = require('./elements').VOID
var CONTAINER_ELEMENTS = require('./elements').CONTAINER
Expand Down Expand Up @@ -30,7 +31,7 @@ module.exports = function init (modules) {
}

if (!vnode.sel && vnode.text) {
return vnode.text
return escape(vnode.text)
}

vnode.data = vnode.data || {}
Expand Down Expand Up @@ -68,7 +69,7 @@ module.exports = function init (modules) {
if (vnode.data.props && vnode.data.props.innerHTML) {
tag.push(vnode.data.props.innerHTML)
} else if (vnode.text) {
tag.push(vnode.text)
tag.push(escape(vnode.text))
} else if (vnode.children) {
vnode.children.forEach(function (child) {
tag.push(renderToString(child))
Expand Down
12 changes: 12 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,15 @@ test('Custom CSS properties', function (t) {

t.end()
})

test('Escape HTML in the text content', function (t) {
var vnode = h('div', ['<p></p>'])

t.equal(toHTML(vnode), '<div>&lt;p&gt;&lt;/p&gt;</div>')

vnode = h('div', '<p></p>')

t.equal(toHTML(vnode), '<div>&lt;p&gt;&lt;/p&gt;</div>')

t.end()
})

0 comments on commit 9ac022c

Please sign in to comment.