fix(ivy): i18n - trim whitespace when parsing metadata (#34154)

It is possible for HTML formatters to add whitespace
around the content of `i18n` attribute values. This can
make the meaning and custom ids brittle to simple
whitespace formatting.

This commit ensures that the metadata string extracted
from HTML `i18n` attributes is trimmed before being parsed
into meaning, description and custom id.

PR Close #34154
This commit is contained in:
Pete Bacon Darwin
2019-12-03 08:36:56 +00:00
committed by Miško Hevery
parent 5cf5843be3
commit f4d714ca0b
2 changed files with 9 additions and 1 deletions

View File

@ -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);