fix: parse ASCII minus in locale-aware number binding#15726
Open
jamesfredley wants to merge 2 commits into
Open
fix: parse ASCII minus in locale-aware number binding#15726jamesfredley wants to merge 2 commits into
jamesfredley wants to merge 2 commits into
Conversation
Accept browser-submitted ASCII hyphen-minus when binding numbers for locales whose DecimalFormat minus sign is U+2212. This keeps display formatting unchanged while allowing Long, BigDecimal, and BigInteger converters to parse negative values for nb_NO. Fixes #15714 Assisted-by: Hephaestus:gpt-5.5 oracle
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes locale-aware request data binding for negative numbers when browsers submit an ASCII hyphen-minus (-, U+002D) but the active locale’s DecimalFormatSymbols.minusSign is a different character (notably U+2212 for locales like nb_NO). It does so by normalizing only a leading ASCII minus to the locale’s expected minus sign before parsing, and adds targeted Spock coverage.
Changes:
- Normalize a leading ASCII
-to the locale-specific minus sign forDecimalFormat-backed parsers inLocaleAwareNumberConverterbefore callingNumberFormat.parse. - Reuse a single formatter instance per conversion and validate parse consumption against the normalized input.
- Add Spock tests covering
Long,BigDecimal, andBigIntegerconversions fornb_NOanden_US.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| grails-databinding/src/main/groovy/org/grails/databinding/converters/web/LocaleAwareNumberConverter.groovy | Normalizes leading ASCII minus to locale minus for DecimalFormat to prevent parse failures in locales with non-ASCII minus signs. |
| grails-databinding/src/test/groovy/org/grails/databinding/converters/web/LocaleAwareNumberConverterSpec.groovy | Adds regression coverage for negative number parsing across nb_NO and en_US for Long, BigDecimal, and BigInteger. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
✅ All tests passed ✅🏷️ Commit: b272702 Learn more about TestLens at testlens.app. |
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.
Summary
Fixes #15714 by accepting browser-submitted ASCII hyphen-minus values in locale-aware number binding for locales whose DecimalFormat minus sign is U+2212, such as nb_NO.
The earlier PR #15475 correctly scoped the rendering fix to form field input output, but #15714 shows the remaining failure is on the request binding side. The sample application's proposed direction was right: convert a leading ASCII minus to the active locale minus before calling NumberFormat.parse, instead of changing display tags.
Changes
Verification