diff --git a/packages/container/lib/registry.js b/packages/container/lib/registry.js index 79248b760a9..3e102c2592f 100644 --- a/packages/container/lib/registry.js +++ b/packages/container/lib/registry.js @@ -5,7 +5,7 @@ import EmptyObject from 'ember-metal/empty_object'; import assign from 'ember-metal/assign'; import Container from './container'; -var VALID_FULL_NAME_REGEXP = /^[^:]+.+:[^:]+$/; +var VALID_FULL_NAME_REGEXP = /^[^:]+:[^:]+$/; /** A registry used to store factory and option information keyed @@ -345,7 +345,9 @@ Registry.prototype = { @return {Boolean} */ has(fullName, options) { - assert('fullName must be a proper full name', this.validateFullName(fullName)); + if (!this.isValidFullName(fullName)) { + return false; + } let source; if (isEnabled('ember-htmlbars-local-lookup')) { @@ -693,12 +695,17 @@ Registry.prototype = { }, validateFullName(fullName) { - if (!VALID_FULL_NAME_REGEXP.test(fullName)) { + if (!this.isValidFullName(fullName)) { throw new TypeError('Invalid Fullname, expected: `type:name` got: ' + fullName); } + return true; }, + isValidFullName(fullName) { + return !!VALID_FULL_NAME_REGEXP.test(fullName); + }, + validateInjections(injections) { if (!injections) { return; } diff --git a/packages/container/tests/registry_test.js b/packages/container/tests/registry_test.js index 9963e67fc34..0d011965153 100644 --- a/packages/container/tests/registry_test.js +++ b/packages/container/tests/registry_test.js @@ -124,6 +124,8 @@ QUnit.test('The registry normalizes names when checking if the factory is regist }); QUnit.test('validateFullName throws an error if name is incorrect', function() { + expect(2); + var registry = new Registry(); var PostController = factory(); @@ -133,8 +135,12 @@ QUnit.test('validateFullName throws an error if name is incorrect', function() { registry.register('controller:post', PostController); throws(function() { - registry.resolve('post'); + registry.validateFullName('post'); }, /TypeError: Invalid Fullname, expected: `type:name` got: post/); + + throws(function() { + registry.validateFullName('route:http://foo.bar.com/baz'); + }, /TypeError: Invalid Fullname, expected: `type:name` got: route:http:\/\/foo.bar.com\/baz/); }); QUnit.test('The registry normalizes names when injecting', function() { @@ -205,6 +211,14 @@ QUnit.test('registry.has should not accidentally cause injections on that factor ok(registry.has('controller:apple')); }); +QUnit.test('registry.has should not error for invalid fullNames)', function() { + expect(1); + + var registry = new Registry(); + + ok(!registry.has('foo:bar:baz')); +}); + QUnit.test('once resolved, always return the same result', function() { expect(1);