Fix bug in DirectiveParser: should not extract translate pipe in html tag

This commit is contained in:
Kim Biesbjerg 2016-12-10 04:14:13 +01:00
parent 4307e4bde8
commit 43df1f0fb8
2 changed files with 10 additions and 2 deletions

View File

@ -18,9 +18,11 @@ export class DirectiveParser extends AbstractTemplateParser implements ParserInt
let collection: TranslationCollection = new TranslationCollection(); let collection: TranslationCollection = new TranslationCollection();
template = this._normalizeTemplateAttributes(template); template = this._normalizeTemplateAttributes(template);
const selector = '[translate], [ng2-translate]';
$(template) $(template)
.find('[translate], [ng2-translate]') .find(selector)
.addBack() .addBack(selector)
.each((i: number, element: CheerioElement) => { .each((i: number, element: CheerioElement) => {
const $element = $(element); const $element = $(element);
const attr = $element.attr('translate') || $element.attr('ng2-translate'); const attr = $element.attr('translate') || $element.attr('ng2-translate');

View File

@ -98,4 +98,10 @@ describe('DirectiveParser', () => {
expect(keys).to.deep.equal(['KEY']); expect(keys).to.deep.equal(['KEY']);
}); });
it('should not extract translate pipe in html tag', () => {
const contents = `<p>{{ 'Audiobooks for personal development' | translate }}</p>`;
const collection = parser.extract(contents, templateFilename);
expect(collection.values).to.deep.equal({});
});
}); });