Skip to content

Commit

Permalink
Skip function inside object while encoding, just like JSON.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Nov 18, 2014
1 parent b613485 commit b10e282
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ function msgpack() {
, header

for (key in obj) {
if (obj.hasOwnProperty(key) && obj[key] !== undefined) {
if (obj.hasOwnProperty(key) &&
obj[key] !== undefined &&
"function" !== typeof obj[key] ) {
++length
acc.push(encode(key))
acc.push(encode(obj[key]))
Expand Down
18 changes: 18 additions & 0 deletions test/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

var test = require('tape').test
, msgpack = require('../')
, noop = function() {}

test('encode a function inside a map', function(t) {
var encoder = msgpack()
, expected = {
hello: 'world'
}
, toEncode = {
hello: 'world'
, func: noop
}

t.deepEqual(encoder.decode(encoder.encode(toEncode)), expected, 'remove the function from the map');
t.end()
})

0 comments on commit b10e282

Please sign in to comment.