From 917ed96ea9637835415a0a7e70e507ae7530b03c Mon Sep 17 00:00:00 2001 From: John Opferkuch Date: Fri, 15 Jul 2016 20:24:45 -0700 Subject: [PATCH] Fix for issue 215: https://github.com/SteveSanderson/knockout.mapping/issues/215 check that lookup key doesn't step on Object.prototype --- knockout.mapping.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/knockout.mapping.js b/knockout.mapping.js index 2ac4a3d..96f0d17 100644 --- a/knockout.mapping.js +++ b/knockout.mapping.js @@ -792,7 +792,7 @@ var findBucket = function(key) { var bucketKey; try { - bucketKey = key;//JSON.stringify(key); + bucketKey = validatedBucketKey(key);//JSON.stringify(key); } catch (e) { bucketKey = "$$$"; @@ -805,6 +805,20 @@ } return bucket; }; + + //make sure the key doesn't step on Object.prototype: + var validatedBucketKey = function(key) + { + if ((typeof key === 'string' || key instanceof String) && + Object.prototype.hasOwnProperty(key) ) + { + return "$$"+ key + "$$"; + } + else + { + return key; + } + } this.save = function (key, value) { findBucket(key).save(key, value);