ListFormat validates patterns before passing them to MessageFormat, but it 
currently allows single quotes as is. MessageFormat interprets these as 
escaping syntax, which can lead to incorrect output. For example, given the end 
pattern  `"{0}'{1}'"` and an empty two pattern, a `ListFormat` formats 
`List.of("foo", "bar")` as `"foo{1}"` instead of `"foo'bar'"`.

This behavior violates the specification, as ListFormat does not define any 
escaping mechanisms. This PR converts ListFormat patterns to the corresponding 
MessageFormat pattern by ensuring all single quotes are doubled, such that they 
are always treated literally by the MessageFormat. I intentionally handle the 
replacement logic at the MessageFormat creation site instead of the existing 
ListFormat validation, because the patterns should remain exactly the same as 
the input given by the user.

I am treating this as a normal bug fix since the current behavior violates the 
specification and is incorrect. No one should be relying on this type of 
behavior. However, I can file a CSR if deemed necessary.

---------
- [x] I confirm that I make this contribution in accordance with the [OpenJDK 
Interim AI Policy](https://openjdk.org/legal/ai).

-------------

Commit messages:
 - init

Changes: https://git.openjdk.org/jdk/pull/31430/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=31430&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8386200
  Stats: 36 lines in 2 files changed: 29 ins; 0 del; 7 mod
  Patch: https://git.openjdk.org/jdk/pull/31430.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/31430/head:pull/31430

PR: https://git.openjdk.org/jdk/pull/31430

Reply via email to