fix(CssSelector): fix `getMatchingElementTemplate()` for void tags

fixes #11407
This commit is contained in:
Victor Berchet 2016-09-07 15:40:00 -07:00 committed by Evan Martin
parent a52d076912
commit 077e0be1e7
2 changed files with 9 additions and 1 deletions

View File

@ -9,6 +9,7 @@
import {ListWrapper} from './facade/collection';
import {StringWrapper, isBlank, isPresent} from './facade/lang';
import {getHtmlTagDefinition} from './ml_parser/html_tags';
const _EMPTY_ATTR_VALUE = '';
@ -101,7 +102,8 @@ export class CssSelector {
attrs += ` ${attrName}${attrValue}`;
}
return `<${tagName}${classAttr}${attrs}></${tagName}>`;
return getHtmlTagDefinition(tagName).isVoid ? `<${tagName}${classAttr}${attrs}/>` :
`<${tagName}${classAttr}${attrs}></${tagName}>`;
}
addAttribute(name: string, value: string = _EMPTY_ATTR_VALUE) {

View File

@ -374,5 +374,11 @@ export function main() {
expect(template).toEqual('<grape></grape>');
});
it('should support void tags', () => {
const selector = CssSelector.parse('input[fancy]')[0];
const template = selector.getMatchingElementTemplate();
expect(template).toEqual('<input fancy/>');
});
});
}