Skip to content

Commit

Permalink
Fix for issue 215: SteveSanderson#215 check that lookup key doesn't s…
Browse files Browse the repository at this point in the history
…tep on Object.prototype
  • Loading branch information
opfertunes committed Jul 16, 2016
1 parent 92f2649 commit 917ed96
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion knockout.mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "$$$";
Expand All @@ -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);
Expand Down

0 comments on commit 917ed96

Please sign in to comment.