Skip to content

Commit

Permalink
fix(coreDirectives): Added an Error Message for invalid selectors on …
Browse files Browse the repository at this point in the history
…component annotation

If the component selector is an empty string or not a string an error will be thrown.

Closes angular#3464
  • Loading branch information
Daniel Rasmuson committed Oct 28, 2015
1 parent a881f09 commit 791df85
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions modules/angular2/src/core/compiler/selector.ts
Expand Up @@ -2,6 +2,7 @@ import {Map, ListWrapper, MapWrapper} from 'angular2/src/core/facade/collection'
import {
isPresent,
isBlank,
isString,
RegExpWrapper,
RegExpMatcherWrapper,
StringWrapper
Expand Down Expand Up @@ -32,6 +33,10 @@ export class CssSelector {
notSelectors: CssSelector[] = [];

static parse(selector: string): CssSelector[] {
if (StringWrapper.equals(selector, '')) {
throw new BaseException('Selectors must not be an empty string');
}

var results: CssSelector[] = [];
var _addResult = (res: CssSelector[], cssSel) => {
if (cssSel.notSelectors.length > 0 && isBlank(cssSel.element) &&
Expand Down
5 changes: 5 additions & 0 deletions modules/angular2/test/core/compiler/selector_spec.ts
Expand Up @@ -230,6 +230,11 @@ export function main() {
expect(matched.length).toEqual(2);
expect(matched).toEqual([s1[0], 1]);
});

it('should throw an error if the selector is an empty string', () => {
expect(function() { CssSelector.parse(''); })
.toThrowError('Selectors must not be an empty string');
});
});

describe('CssSelector.parse', () => {
Expand Down

0 comments on commit 791df85

Please sign in to comment.