Skip to content

Commit

Permalink
fix(compiler): allow single quotes into named interpolations
Browse files Browse the repository at this point in the history
The regex that extract named interpolations for i18n placeholders only allowed double quotes, this PR adds the ability to use single quotes

Fixes angular#15318
  • Loading branch information
ocombe committed Mar 24, 2017
1 parent c2892da commit cd5085d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/compiler/src/i18n/i18n_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
6 changes: 6 additions & 0 deletions packages/compiler/test/i18n/i18n_parser_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ export function main() {
.toEqual([
[['[before, <ph name="TEST"> exp //i18n(ph="teSt") </ph>, after]'], 'm', 'd'],
]);

expect(
_humanizeMessages('<div i18n=\'m|d\'>before{{ exp //i18n(ph=\'teSt\') }}after</div>'))
.toEqual([
[[`[before, <ph name="TEST"> exp //i18n(ph='teSt') </ph>, after]`], 'm', 'd'],
]);
});
});

Expand Down

0 comments on commit cd5085d

Please sign in to comment.