SkeLLLa/node-object-hash

Throws on an empty object without prototype

futpib opened this issue · 1 comments

require('node-object-hash')().hash(Object.create(null))
TypeError: Cannot read property 'name' of undefined
    at _guessObjectType (.../node-object-hash/objectSorter.js:20:27)
    at _guessType (.../node-object-hash/objectSorter.js:68:37)
    at objectToString (.../node-object-hash/objectSorter.js:213:24)
    at sortObject (.../node-object-hash/index.js:78:12)
    at Object.hashObject [as hash] (.../node-object-hash/index.js:103:18

Here is the offending line (20):

function _guessObjectType(obj) {
if (obj === null) {
return 'null';
}
switch (obj.constructor.name) {
case 'Array':

This assumes that every (non-null) object has as constructor property, which is not generally the case.