Skip to content

Keep numberFormat patterns as written - #1212

Open
b84330808 wants to merge 1 commit into
jknack:masterfrom
b84330808:fix-numberformat-pattern-case
Open

b84330808 wants to merge 1 commit into
jknack:masterfrom
b84330808:fix-numberformat-pattern-case

Conversation

@b84330808

Copy link
Copy Markdown

Since 4.5.0 (#1161), numberFormat upper-cases the format argument before it passes the argument to DecimalFormat. As a result, literal text in a pattern changes case:

{{numberFormat 3.14159 "#,##0.00 'items'"}}
  • 4.4.0: 3.14 items
  • 4.5.0 to 4.5.6: 3.14 ITEMS

With this PR, only the lookup of the integer/percent/currency styles uses the upper-cased copy. DecimalFormat gets the pattern as written, as it did in 4.4.0.

The style lookup and the roundingMode lookup also use Locale.ROOT now. With a Turkish default locale, two things went wrong:

  • "integer" became "İNTEGER". It no longer matched a style, so it was used as a pattern and rendered İNTEGER3.
  • roundingMode="ceiling" failed with No enum constant java.math.RoundingMode.CEİLİNG.

Tests: NumberFormatTest.patternWithLiteralText and NumberFormatTest.namesDoNotDependOnDefaultLocale fail on master and pass with this change. mvn -pl handlebars test passes: 1064 tests, with the same 3 skipped as before. spotless:check is clean.

Since 4.5.0 the numberFormat helper upper-cased the format argument
before using it as a DecimalFormat pattern, so literal text changed
case: "#,##0.00 'items'" rendered "3.14 ITEMS". Upper-case only the
copy used to look up the integer/percent/currency/default styles, and
pass the original string to DecimalFormat as before 4.5.0.

The style lookup and the roundingMode lookup now use Locale.ROOT, so
"integer" and roundingMode="ceiling" keep working when the default
locale is Turkish.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant