fix(localize): allow ICU expansion case to start with any character except `}` (#36123)
Previously, an expansion case could only start with an alpha numeric character. This commit fixes this by allowing an expansion case to start with any character except `}`. The [ICU spec](http://userguide.icu-project.org/formatparse/messages) is pretty vague: > Use a "select" argument to select sub-messages via a fixed set of keywords. It does not specify what can be a "keyword" but from looking at the surrounding syntax it appears that it can indeed be any string that does not contain a `}` character. Closes #31586 PR Close #36123
This commit is contained in:
parent
1cb7b88505
commit
fced8ee40e
|
@ -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 {
|
||||
|
|
|
@ -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});
|
||||
|
|
Loading…
Reference in New Issue