Trim leading/trailing whitespace. Closes #175

This commit is contained in:
Kim Biesbjerg 2020-03-31 12:24:57 +02:00
parent 05d1917f9d
commit 3bf2aaca4e
2 changed files with 19 additions and 1 deletions

View File

@ -82,6 +82,6 @@ export class DirectiveParser implements ParserInterface {
} }
protected cleanKey(val: string): string { protected cleanKey(val: string): string {
return val.replace(/\r?\n|\r|\t/g, ''); return val.replace(/\r?\n|\r|\t/g, '').trim();
} }
} }

View File

@ -117,4 +117,22 @@ describe('DirectiveParser', () => {
const keys = parser.extract(contents, templateFilename).keys(); const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal(['client.search.searchBtn']); expect(keys).to.deep.equal(['client.search.searchBtn']);
}); });
it('should extract contents without indent spaces and trim leading/trailing whitespace', () => {
const contents = `
<div translate>
this is an example
of a long label
</div>
<div>
<p translate>
this is an example
of a long label
</p>
</div>
`;
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal(['this is an example of a long label']);
});
}); });