Repository navigation
core: make NumberUtils.formatDouble locale-independent (#150) - #174
Merged
Merged
Conversation
DecimalFormat's no-symbols constructor uses the JVM default FORMAT locale, so formatDouble(0.5) returned "0,5" on a JVM running with e.g. -Duser.language=fr. The browser always reports "0.5" for a native input's value/step/min/max, so every fractional assertion in ProgressBarElement, SliderElement and NumberFieldElement failed for consumers of the library. The repo's own suite never caught it because ApplicationServiceInitListener sets Locale.UK in the IT JVM. Pass DecimalFormatSymbols.getInstance(Locale.ROOT) so the decimal separator is always ".", and add a unit test that covers both a Locale.setDefault(Locale.FRANCE) default and a FORMAT-category-only override. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Fixes #150.
Problem
NumberUtils.formatDoublebuilt its formatter withnew DecimalFormat("0.######"), whose no-symbols constructor picks upLocale.getDefault(Locale.Category.FORMAT). On a JVM running with e.g.-Duser.language=fr,formatDouble(0.5)returned"0,5"while the browser always reports"0.5"for a native input'svalue/step/min/max.That broke every fractional assertion for consumers of the library, across all three affected elements:
ProgressBarElement—assertValue/assertMin/assertMax(aria-value*)SliderElement—assertValue/assertMin/assertMax/assertStepNumberFieldElement—assertStep/assertMin/assertMaxThe repo's own suite never caught it:
ApplicationServiceInitListenercallsLocale.setDefault(Locale.UK)in the same JVM that runs the ITs.Fix
Pass explicit ROOT symbols so the decimal separator is always
.:Test
New
NumberUtilsTest— the first plain unit test in the repo; surefire runs it via the JUnit engine already pulled in byspring-boot-starter-test. Five cases: whole values, fractional values, aLocale.FRANCEdefault, a FORMAT-category-only override (whichLocale.setDefault(Locale)alone would miss), and no scientific notation for0.000001. Each test restores both the default and the FORMAT-category locale in@AfterEachso nothing leaks into the IT JVM.Verified the test actually pins the behaviour: with the fix reverted, the two locale cases fail with
expected: <0.5> but was: <0,5>; with it in place all five pass.🤖 Generated with Claude Code