Skip to content

Commit

Permalink
Fix SteveSanderson#124 - Use hasOwnProperty to check for bucket exist…
Browse files Browse the repository at this point in the history
…ence

If a mapped observable has a value that is a property of `Object.prototype`,
`findBucket` returns that property's value instead of a `simpleObjectLookup`
instance.
  • Loading branch information
lawnsea authored and crissdev committed Feb 13, 2015
1 parent db6424f commit 1cf041d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/knockout.mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@
}

var bucket = buckets[bucketKey];
if (bucket === undefined) {
if (!buckets.hasOwnProperty(bucketKey)) {
bucket = new SimpleObjectLookup();
buckets[bucketKey] = bucket;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/knockout.mapping.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/knockout.mapping.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion knockout.mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@
}

var bucket = buckets[bucketKey];
if (bucket === undefined) {
if (!buckets.hasOwnProperty(bucketKey)) {
bucket = new SimpleObjectLookup();
buckets[bucketKey] = bucket;
}
Expand Down
7 changes: 7 additions & 0 deletions spec/issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,11 @@ QUnit.test('Issue #203', function(assert) {

assert.deepEqual(ko.mapping.toJS(viewModel), {connectionId: 1, type: 'thirdType', thirdTypeProperty: 'thirdTypeProperty'});
});

//https://github.com/SteveSanderson/knockout.mapping/issues/124
QUnit.test('Issue #124', function(assert) {
var model = ko.mapping.fromJS({ foo: 'constructor' });
assert.equal(model.foo(), 'constructor');
});

})();

0 comments on commit 1cf041d

Please sign in to comment.