From 04596e8aa02088896bd1be090d208646dbe84dc1 Mon Sep 17 00:00:00 2001 From: Ryan Niemeyer Date: Wed, 8 Apr 2015 13:51:45 -0500 Subject: [PATCH] Component defaultLoader should use hasOwnProperty for isRegistered check --- spec/components/defaultLoaderBehaviors.js | 8 ++++++++ src/components/defaultLoader.js | 8 ++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/spec/components/defaultLoaderBehaviors.js b/spec/components/defaultLoaderBehaviors.js index 352e1b25c..a927f3f20 100644 --- a/spec/components/defaultLoaderBehaviors.js +++ b/spec/components/defaultLoaderBehaviors.js @@ -18,6 +18,14 @@ describe('Components: Default loader', function() { expect(ko.components.isRegistered(testComponentName)).toBe(false); }); + it('Allows registering component names that may conflict with properties on Object.prototype', function() { + var prototypeProperty = 'toString'; + + expect(ko.components.isRegistered(prototypeProperty)).toBe(false); + ko.components.register(prototypeProperty, {}); + expect(ko.components.isRegistered(prototypeProperty)).toBe(true); + }); + it('Throws if you try to register a component that is already registered', function() { ko.components.register(testComponentName, {}); diff --git a/src/components/defaultLoader.js b/src/components/defaultLoader.js index 1169a4b7d..2db2cf529 100644 --- a/src/components/defaultLoader.js +++ b/src/components/defaultLoader.js @@ -22,16 +22,16 @@ } defaultConfigRegistry[componentName] = config; - } + }; ko.components.isRegistered = function(componentName) { - return componentName in defaultConfigRegistry; - } + return defaultConfigRegistry.hasOwnProperty(componentName); + }; ko.components.unregister = function(componentName) { delete defaultConfigRegistry[componentName]; ko.components.clearCachedDefinition(componentName); - } + }; ko.components.defaultLoader = { 'getConfig': function(componentName, callback) {