Use non-greedy regular expression
This commit is contained in:
parent
788d9ed4d3
commit
fbbfa04a34
@ -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)) {
|
||||
|
@ -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...']);
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user