Skip to content

Commit

Permalink
ICU4C: Allow trailing whitespace after a match
Browse files Browse the repository at this point in the history
  • Loading branch information
catamorphism committed Jul 31, 2024
1 parent d518e5f commit 0436018
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
16 changes: 4 additions & 12 deletions icu4c/source/i18n/messageformat2_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2098,18 +2098,10 @@ void Parser::parseSelectors(UErrorCode& status) {

// Parse variants
while (isWhitespace(source[index]) || isKeyStart(source[index])) {
if (isWhitespace(source[index])) {
int32_t whitespaceStart = index;
parseOptionalWhitespace(status);
// Restore the precondition.
// Error out if we reached the end of input. The message
// cannot end with trailing whitespace if there are variants.
if (!inBounds(source, index)) {
// Use index of first whitespace for error message
index = whitespaceStart;
ERROR(parseError, status, index);
return;
}
// Trailing whitespace is allowed
parseOptionalWhitespace(status);
if (!inBounds(source, index)) {
return;
}

// At least one key is required
Expand Down
5 changes: 0 additions & 5 deletions testdata/message2/syntax-errors-diagnostics.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,6 @@
"char": 28,
"comment": "Trailing characters that are not whitespace"
},
{
"src": ".match {$foo :string} {$bar :string} one * {{one}} * * {{other}} ",
"char": 66,
"comment": "Trailing whitespace at end of message should not be accepted either"
},
{
"src": "empty { }",
"char": 8,
Expand Down
5 changes: 5 additions & 0 deletions testdata/message2/valid-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@
"comment": "Test that parser and serializer treat optionally-escaped characters consistently",
"src" : "{{{1}|}}",
"exp": "1|"
},
{
"comment": "Trailing whitespace after match is valid",
"src": ".match {1 :string} * {{}} ",
"exp": ""
}
]
}

0 comments on commit 0436018

Please sign in to comment.