diff --git a/CHANGELOG b/CHANGELOG index 67dc3c6..92f58bf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Ensure Hash does not return keys from the prototype chain (e.g., constructor, valueOf, toString). (kangax) + * Fix toString/valueOf sharing same method reference via closure in Class#addMethods. Use plain property assignment, since Object.extend fails to enumerate over toString/valueOf. (kangax) * Stop Form.Element.disable from stealing focus. (jddalton) diff --git a/src/hash.js b/src/hash.js index 125a96b..ed96637 100644 --- a/src/hash.js +++ b/src/hash.js @@ -28,7 +28,9 @@ var Hash = Class.create(Enumerable, (function() { }, get: function(key) { - return this._object[key]; + // simulating poorly supported hasOwnProperty + if (this._object[key] !== Object.prototype[key]) + return this._object[key]; }, unset: function(key) { diff --git a/test/unit/hash_test.js b/test/unit/hash_test.js index f67ebca..cc3d083 100644 --- a/test/unit/hash_test.js +++ b/test/unit/hash_test.js @@ -14,6 +14,9 @@ new Test.Unit.Runner({ this.assertEqual('A', h.get('a')); this.assertUndefined(h.a); this.assertUndefined($H({}).get('a')); + + this.assertUndefined($H({}).get('toString')); + this.assertUndefined($H({}).get('constructor')); }, testUnset: function() {