diff --git a/packages/compiler/src/render3/view/i18n/meta.ts b/packages/compiler/src/render3/view/i18n/meta.ts index 98e2ac1329..6269e69e27 100644 --- a/packages/compiler/src/render3/view/i18n/meta.ts +++ b/packages/compiler/src/render3/view/i18n/meta.ts @@ -201,11 +201,12 @@ const I18N_ID_SEPARATOR = '@@'; * @param meta String that represents i18n meta * @returns Object with id, meaning and description fields */ -export function parseI18nMeta(meta?: string): I18nMeta { +export function parseI18nMeta(meta: string = ''): I18nMeta { let customId: string|undefined; let meaning: string|undefined; let description: string|undefined; + meta = meta.trim(); if (meta) { const idIndex = meta.indexOf(I18N_ID_SEPARATOR); const descIndex = meta.indexOf(I18N_MEANING_SEPARATOR); diff --git a/packages/compiler/test/render3/view/i18n_spec.ts b/packages/compiler/test/render3/view/i18n_spec.ts index a4660926ce..afa3778075 100644 --- a/packages/compiler/test/render3/view/i18n_spec.ts +++ b/packages/compiler/test/render3/view/i18n_spec.ts @@ -207,6 +207,13 @@ describe('Utils', () => { expect(parseI18nMeta('meaning|desc')).toEqual(meta('', 'meaning', 'desc')); expect(parseI18nMeta('meaning|desc@@id')).toEqual(meta('id', 'meaning', 'desc')); expect(parseI18nMeta('@@id')).toEqual(meta('id', '', '')); + + expect(parseI18nMeta('\n ')).toEqual(meta()); + expect(parseI18nMeta('\n desc\n ')).toEqual(meta('', '', 'desc')); + expect(parseI18nMeta('\n desc@@id\n ')).toEqual(meta('id', '', 'desc')); + expect(parseI18nMeta('\n meaning|desc\n ')).toEqual(meta('', 'meaning', 'desc')); + expect(parseI18nMeta('\n meaning|desc@@id\n ')).toEqual(meta('id', 'meaning', 'desc')); + expect(parseI18nMeta('\n @@id\n ')).toEqual(meta('id', '', '')); }); it('serializeI18nHead()', () => {