Skip to content

Commit 97a2d96

Browse files
committed
Merge pull request #13356 from rwjblue/beef-up-regexp
[BUGFIX beta] Update Registry#has to always return true/false.
2 parents 5389442 + d0619b8 commit 97a2d96

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

packages/container/lib/registry.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import EmptyObject from 'ember-metal/empty_object';
55
import assign from 'ember-metal/assign';
66
import Container from './container';
77

8-
var VALID_FULL_NAME_REGEXP = /^[^:]+.+:[^:]+$/;
8+
var VALID_FULL_NAME_REGEXP = /^[^:]+:[^:]+$/;
99

1010
/**
1111
A registry used to store factory and option information keyed
@@ -345,7 +345,9 @@ Registry.prototype = {
345345
@return {Boolean}
346346
*/
347347
has(fullName, options) {
348-
assert('fullName must be a proper full name', this.validateFullName(fullName));
348+
if (!this.isValidFullName(fullName)) {
349+
return false;
350+
}
349351

350352
let source;
351353
if (isEnabled('ember-htmlbars-local-lookup')) {
@@ -693,12 +695,17 @@ Registry.prototype = {
693695
},
694696

695697
validateFullName(fullName) {
696-
if (!VALID_FULL_NAME_REGEXP.test(fullName)) {
698+
if (!this.isValidFullName(fullName)) {
697699
throw new TypeError('Invalid Fullname, expected: `type:name` got: ' + fullName);
698700
}
701+
699702
return true;
700703
},
701704

705+
isValidFullName(fullName) {
706+
return !!VALID_FULL_NAME_REGEXP.test(fullName);
707+
},
708+
702709
validateInjections(injections) {
703710
if (!injections) { return; }
704711

packages/container/tests/registry_test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ QUnit.test('The registry normalizes names when checking if the factory is regist
124124
});
125125

126126
QUnit.test('validateFullName throws an error if name is incorrect', function() {
127+
expect(2);
128+
127129
var registry = new Registry();
128130
var PostController = factory();
129131

@@ -133,8 +135,12 @@ QUnit.test('validateFullName throws an error if name is incorrect', function() {
133135

134136
registry.register('controller:post', PostController);
135137
throws(function() {
136-
registry.resolve('post');
138+
registry.validateFullName('post');
137139
}, /TypeError: Invalid Fullname, expected: `type:name` got: post/);
140+
141+
throws(function() {
142+
registry.validateFullName('route:http://foo.bar.com/baz');
143+
}, /TypeError: Invalid Fullname, expected: `type:name` got: route:http:\/\/foo.bar.com\/baz/);
138144
});
139145

140146
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
205211
ok(registry.has('controller:apple'));
206212
});
207213

214+
QUnit.test('registry.has should not error for invalid fullNames)', function() {
215+
expect(1);
216+
217+
var registry = new Registry();
218+
219+
ok(!registry.has('foo:bar:baz'));
220+
});
221+
208222
QUnit.test('once resolved, always return the same result', function() {
209223
expect(1);
210224

0 commit comments

Comments
 (0)