SocketCluster / socketcluster-client

JavaScript client for SocketCluster
MIT License
293 stars 91 forks source link

ancestors is an array, there is no need to use for-in #48

Closed mauritslamers closed 8 years ago

mauritslamers commented 8 years ago

This replaces the isOwnDescendant circular reference check. The original implementation uses a for-in loop, which would also check against properties on the array. If an app is used for the first time, the first request will send an authKey having value null. The request is stringified and checked by the convertBuffersToBase64 function. When the authKey is null, at one point the value of object will become null. When however a property exists on the ancestors array (which can happen if used with a framework which touches Array.prototype) which has null as value, isOwnDescendant thinks that null has a descendant and this will cause convertBuffersToBase64 to throw an error. I ran into this because I used an older version which did not have the ancestors.hasOwnProperty() check and therefore ran up the prototype chain.

jondubois commented 8 years ago

I can't merge this PR because the change had to be made in a different repo (a dependency): https://github.com/SocketCluster/sc-formatter/blob/master/index.js#L37

I copied your change into the appropriate place though so it's all merged in now. Thanks.