[LANG-1827] Support escaped single quotes ('') in DurationFormatUtils format patterns#1700
Open
sarankumarbaskar wants to merge 2 commits into
Open
Conversation
Member
|
@ppkarwasz @chtompki |
garydgregory
requested changes
Jun 15, 2026
garydgregory
left a comment
Member
There was a problem hiding this comment.
Hello @Sarankumar18
Please see my comment.
Thank you!
| } | ||
|
|
||
| @Test | ||
| void testLANG1827() { |
Member
There was a problem hiding this comment.
Hello @Sarankumar18
Please write this new test as a @ParameterizedTest so that we can run all input/output individually and see them all fail if the main side of the patch is not applied.
Author
There was a problem hiding this comment.
@garydgregory I've made as parametrize test for testLANG1827
Run each DurationFormatUtils escaped quote case independently.
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.
DurationFormatUtils.lexx() does not handle escaped single quotes, making it
impossible to include a literal apostrophe in formatted duration output.
The root cause is in the lexx() parser: when it encounters a single quote
while inside a literal block, it unconditionally ends the literal. It never
checks whether the next character is also a single quote, which should mean
"emit a literal apostrophe and continue the literal."
This behavior contradicts the quoting convention established by
java.text.SimpleDateFormat, where '' consistently produces a literal
single quote. The class Javadoc acknowledged the limitation explicitly:
and a TODO in lexx() read:
This PR modifies lexx() to recognise '' as an escaped single quote — both
inside and outside quoted literal sections — matching SimpleDateFormat
behavior. The Javadoc has been updated to document the '' convention and
the TODO has been removed.
Note: This is a minor behavioral change. Existing format strings that relied
on '' as "close one literal then open another" will now produce a literal
apostrophe instead. This aligns with what most users would expect.
This issue is tracked asLANG-1827.
mvn.