diff --git a/build-scripts/gulp/download_translations.js b/build-scripts/gulp/download_translations.js index 6b13474e28..e25ac8ca97 100644 --- a/build-scripts/gulp/download_translations.js +++ b/build-scripts/gulp/download_translations.js @@ -16,6 +16,11 @@ function hasHtml(data) { return /<[a-z][\s\S]*>/i.test(data); } +function hasUnquotedHTags(data) { + // Guard against unquoted HTML tags https://github.com/formatjs/formatjs/issues/1878 + return /[^'](<.*>)[^']/i.test(data); +} + function recursiveCheckHasHtml(file, data, errors, recKey) { Object.keys(data).forEach(function (key) { if (typeof data[key] === "object") { @@ -23,6 +28,10 @@ function recursiveCheckHasHtml(file, data, errors, recKey) { recursiveCheckHasHtml(file, data[key], errors, nextRecKey); } else if (hasHtml(data[key])) { errors.push(`HTML found in ${file.path} at key ${recKey}.${key}`); + } else if (hasUnquotedHTags(data[key])) { + errors.push( + `Unquoted tags found in ${file.path} at key ${recKey}.${key}` + ); } }); } diff --git a/src/common/translations/localize.ts b/src/common/translations/localize.ts index 92267c7eff..696a765872 100644 --- a/src/common/translations/localize.ts +++ b/src/common/translations/localize.ts @@ -64,7 +64,7 @@ export const computeLocalize = ( if (!translatedMessage) { translatedMessage = new IntlMessageFormat( - translatedValue.replace(/[^'](<.*>)[^']/g, "'$1'"), + translatedValue, language, formats );