Skip to content

Commit ba55afb

Browse files
committed
fix(client): does not throws an error for non DOM object that has tagName property
fixes #2139
1 parent 13368e6 commit ba55afb

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

client/stringify.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
var serialize = require('dom-serialize')
22
var instanceOf = require('./util').instanceOf
3+
var isNode = function (obj) {
4+
return (obj.tagName || obj.nodeName) && obj.nodeType
5+
}
36

47
var stringify = function stringify (obj, depth) {
58
if (depth === 0) {
@@ -38,7 +41,7 @@ var stringify = function stringify (obj, depth) {
3841
return '<!--' + obj.nodeValue + '-->'
3942
} else if (obj.outerHTML) {
4043
return obj.outerHTML
41-
} else if (obj.tagName || obj.nodeName) {
44+
} else if (isNode(obj)) {
4245
return serialize(obj)
4346
} else {
4447
var constructor = 'Object'

test/client/stringify.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,8 @@ describe('stringify', function () {
8989

9090
assert.deepEqual(__karma__.stringify([1, 2]), '[1, 2]')
9191
})
92+
93+
it('should stringify object with property tagName as Object', function () {
94+
assert(stringify({tagName: 'a'}).indexOf("{tagName: 'a'}") > -1)
95+
})
9296
})

0 commit comments

Comments
 (0)