Use non-greedy regular expression

This commit is contained in:
Kim Biesbjerg 2016-12-20 16:18:40 +01:00
parent 788d9ed4d3
commit fbbfa04a34
2 changed files with 21 additions and 1 deletions

View File

@ -15,7 +15,7 @@ export class PipeParser extends AbstractTemplateParser implements ParserInterfac
protected _parseTemplate(template: string): TranslationCollection {
let collection: TranslationCollection = new TranslationCollection();
const regExp = new RegExp(/(['"`])([^\1]*)\1\s*\|\s*translate/, 'g');
const regExp = new RegExp(/(['"`])([^\1]*?)\1\s*\|\s*translate/, 'g');
let matches: RegExpExecArray;
while (matches = regExp.exec(template)) {

View File

@ -36,4 +36,24 @@ describe('PipeParser', () => {
expect(keys).to.deep.equal(['Hello World']);
});
it('should not use a greedy regular expression', () => {
const contents = `
<ion-header>
<ion-navbar color="brand">
<ion-title>{{ 'Info' | translate }}</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<content-loading *ngIf="isLoading">
{{ 'Loading...' | translate }}
</content-loading>
</ion-content>
`;
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal(['Info', 'Loading...']);
});
});