diff --git a/index.js b/index.js index 8e30216..afc572f 100644 --- a/index.js +++ b/index.js @@ -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])) diff --git a/test/functions.js b/test/functions.js new file mode 100644 index 0000000..f471f6a --- /dev/null +++ b/test/functions.js @@ -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() +})