From 2d0c5a734f0ba02311682e59c251081c86027370 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 | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/compiler/src/i18n/i18n_parser.ts b/packages/compiler/src/i18n/i18n_parser.ts index cac8435660ebbe..3d0a2dacfc955f 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 070871fa0eb5c9..fef592492d4cca 100644 --- a/packages/compiler/test/i18n/i18n_parser_spec.ts +++ b/packages/compiler/test/i18n/i18n_parser_spec.ts @@ -126,6 +126,14 @@ export function main() { [['[before, exp //i18n(ph="teSt") , after]'], 'm', 'd'], ]); }); + + it('should support named interpolation with single quotes', () => { + expect( + _humanizeMessages('
before{{ exp //i18n(ph=\'teSt\') }}after
')) + .toEqual([ + [['[before, exp //i18n(ph=\'teSt\') , after]'], 'm', 'd'], + ]); + }); }); describe('blocks', () => {