Keep ExtendedMessageFormat from rejecting a quoted format style#1744
Merged
garydgregory merged 1 commit intoJul 7, 2026
Merged
Conversation
garydgregory
added a commit
that referenced
this pull request
Jul 7, 2026
Member
|
@alhudz Thank you, please port to Apache Commons Text if needed. |
Contributor
Author
|
Checked the Commons Text version: its |
Member
|
@alhudz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ExtendedMessageFormat.parseFormatDescriptionwalks a format element's style with aforloop whose update clause always callsnext(pos), but theQUOTEbranch hands off togetQuotedString, which already leavesposone past the closing quote. The loop then advances a second time and skips the character right after that quote, so when a style ends with a quoted literal the terminating}is never seen:depthnever returns to0, the loop runs off the end, and the constructor throwsIllegalArgumentException: Unterminated format element. This only happens on the registry path, sonew ExtendedMessageFormat("{0,number,0'%'}", registry)throws even thoughjava.text.MessageFormatandExtendedMessageFormatwithout a registry both parse that pattern to5%.The fix switches the loop to the
whileform the two sibling parsers in this class already use (applyPattern,insertFormats): advance one position per non-quote branch and let theQUOTEbranch'sgetQuotedStringdo its own advance. Leaving the position arithmetic to the single loop that consumes the quoted run is what stops the double count. The added test fails before the change with theUnterminated format elementexception and passes after.