Fix the byte array sniffing to avoid false positives

This commit is contained in:
Ole André Vadla Ravnås
2015-06-01 01:12:31 +02:00
parent 57fb346877
commit bb0276e272
+8 -4
View File
@@ -358,11 +358,15 @@ WARNING: Unable to find package 'gnureadline' needed for tab completion;
}
function isByteArray(v) {
if (!v || !v.hasOwnProperty('length'))
if (!v || typeof v !== 'object' || typeof v.length !== 'number' || v.length < 1)
return false;
return Array.prototype.every.call(v, function (e) {
return typeof e === 'number';
});
if (v instanceof Array) // Object returned by Memory.readByteArray() isn't an Array
return false;
for (var i = 0; i !== v.length; i++) {
if (typeof v[i] !== 'number')
return false;
}
return true;
}
const onStanza = function (stanza) {