Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(localize): allow ICU expansion to start with any character except… #36123

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/compiler/src/ml_parser/lexer.ts
Expand Up @@ -747,7 +747,7 @@ function isNamedEntityEnd(code: number): boolean {
}

function isExpansionCaseStart(peek: number): boolean {
return peek === chars.$EQ || chars.isAsciiLetter(peek) || chars.isDigit(peek);
return peek !== chars.$RBRACE;
}

function compareCharCodeCaseInsensitive(code1: number, code2: number): boolean {
Expand Down
20 changes: 20 additions & 0 deletions packages/compiler/test/ml_parser/html_parser_spec.ts
Expand Up @@ -313,6 +313,26 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn} from './ast_spe
expect(p.errors.length).toEqual(0);
});

it(`should support ICU expressions with cases that contain any character except '}'`,
() => {
const p = parser.parse(
`{a, select, b {foo} % bar {% bar}}`, 'TestComp', {tokenizeExpansionForms: true});
expect(p.errors.length).toEqual(0);
});

it('should error when expansion case is not properly closed', () => {
const p = parser.parse(
`{a, select, b {foo} % { bar {% bar}}`, 'TestComp', {tokenizeExpansionForms: true});
expect(humanizeErrors(p.errors)).toEqual([
[
6,
'Unexpected character "EOF" (Do you have an unescaped "{" in your template? Use "{{ \'{\' }}") to escape it.)',
'0:36'
],
[null, 'Invalid ICU message. Missing \'}\'.', '0:22']
]);
});

it('should error when expansion case is not closed', () => {
const p = parser.parse(
`{messages.length, plural, =0 {one`, 'TestComp', {tokenizeExpansionForms: true});
Expand Down