From cd5085da255784a75e76a7c7e26c82db84bbf5d5 Mon Sep 17 00:00:00 2001 From: Olivier Combe Date: Fri, 24 Mar 2017 17:07:40 +0100 Subject: [PATCH] fix(compiler): allow single quotes into named interpolations The regex that extract named interpolations for i18n placeholders only allowed double quotes, this PR adds the ability to use single quotes Fixes #15318 --- packages/compiler/src/i18n/i18n_parser.ts | 5 +++-- packages/compiler/test/i18n/i18n_parser_spec.ts | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/compiler/src/i18n/i18n_parser.ts b/packages/compiler/src/i18n/i18n_parser.ts index cac8435660ebb..3d0a2dacfc955 100644 --- a/packages/compiler/src/i18n/i18n_parser.ts +++ b/packages/compiler/src/i18n/i18n_parser.ts @@ -161,8 +161,9 @@ class _I18nVisitor implements html.Visitor { } } -const _CUSTOM_PH_EXP = /\/\/[\s\S]*i18n[\s\S]*\([\s\S]*ph[\s\S]*=[\s\S]*"([\s\S]*?)"[\s\S]*\)/g; +const _CUSTOM_PH_EXP = + /\/\/[\s\S]*i18n[\s\S]*\([\s\S]*ph[\s\S]*=[\s\S]*("|')([\s\S]*?)\1[\s\S]*\)/g; function _extractPlaceholderName(input: string): string { - return input.split(_CUSTOM_PH_EXP)[1]; + return input.split(_CUSTOM_PH_EXP)[2]; } diff --git a/packages/compiler/test/i18n/i18n_parser_spec.ts b/packages/compiler/test/i18n/i18n_parser_spec.ts index 070871fa0eb5c..abbd2d10205ad 100644 --- a/packages/compiler/test/i18n/i18n_parser_spec.ts +++ b/packages/compiler/test/i18n/i18n_parser_spec.ts @@ -125,6 +125,12 @@ export function main() { .toEqual([ [['[before, exp //i18n(ph="teSt") , after]'], 'm', 'd'], ]); + + expect( + _humanizeMessages('
before{{ exp //i18n(ph=\'teSt\') }}after
')) + .toEqual([ + [[`[before, exp //i18n(ph='teSt') , after]`], 'm', 'd'], + ]); }); });