Skip to content

fix: parse ASCII minus in locale-aware number binding#15726

Open
jamesfredley wants to merge 2 commits into
7.1.xfrom
fix/negative-number-binding-locale
Open

fix: parse ASCII minus in locale-aware number binding#15726
jamesfredley wants to merge 2 commits into
7.1.xfrom
fix/negative-number-binding-locale

Conversation

@jamesfredley

Copy link
Copy Markdown
Contributor

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

  • Normalize only a leading ASCII minus in LocaleAwareNumberConverter before parsing.
  • Leave g:formatNumber, g:fieldValue, and form field rendering behavior unchanged.
  • Add Spock coverage for Long, BigDecimal, and BigInteger converters in nb_NO and en_US.

Verification

  • ./gradlew :grails-databinding:test --tests "org.grails.databinding.converters.web.LocaleAwareNumberConverterSpec"
  • ./gradlew :grails-databinding:test
  • Oracle review-gate verdict: GREEN

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
Copilot AI review requested due to automatic review settings June 10, 2026 21:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 for DecimalFormat-backed parsers in LocaleAwareNumberConverter before calling NumberFormat.parse.
  • Reuse a single formatter instance per conversion and validate parse consumption against the normalized input.
  • Add Spock tests covering Long, BigDecimal, and BigInteger conversions for nb_NO and en_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.

@jamesfredley jamesfredley self-assigned this Jun 10, 2026
@jamesfredley jamesfredley moved this to In Progress in Apache Grails Jun 10, 2026
@jamesfredley jamesfredley added this to the grails:7.1.2 milestone Jun 10, 2026
@testlens-app

testlens-app Bot commented Jun 11, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: b272702
▶️ Tests: 5878 executed
⚪️ Checks: 37/37 completed


Learn more about TestLens at testlens.app.

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

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants