Skip to content

Reject trailing characters in DecimalLocaleConverter.parse (1.X)#400

Merged
garydgregory merged 1 commit into
apache:1.Xfrom
rootvector2:decimal-locale-trailing-chars-1.x
Jun 21, 2026
Merged

Reject trailing characters in DecimalLocaleConverter.parse (1.X)#400
garydgregory merged 1 commit into
apache:1.Xfrom
rootvector2:decimal-locale-trailing-chars-1.x

Conversation

@rootvector2

Copy link
Copy Markdown
Contributor

Port of #399 to the 1.X branch.

DecimalLocaleConverter.parse calls DecimalFormat.parse(String), which stops at the first character it cannot read and silently drops the rest, so a locale numeric conversion of 123abc returns 123 and 42 OR 1=1 returns 42. Every numeric locale converter (Byte/Short/Integer/Long/Float/Double/BigDecimal/BigInteger) routes through this one method, while the sibling DateLocaleConverter already rejects leftover input with a ParsePosition check. Switched to that same form so the whole string must be consumed, otherwise ParseException is thrown.

Added DecimalLocaleConverterTest (fails without the runtime change) and updated the now-stale (B) assertions across the numeric locale converter tests, which pinned DecimalFormat's old partial-parse values and now fall through to the converter default.

mvn test -Dtest='*LocaleConverterTest' is green (104 tests). The only failure in a full mvn run is LocaleBeanificationTest.testContextClassloaderIndependence, which is a pre-existing flake unrelated to this change (it fails the same way on a clean 1.X checkout and installs its own mock converters that bypass real parsing).

  • Read the contribution guidelines for this project.
  • Read the ASF Generative Tooling Guidance if you use Artificial Intelligence (AI).
  • I used AI to create any part of, or all of, this pull request. Which AI tool was used to create this pull request, and to what extent did it contribute?
  • Run a successful build using the default Maven goal with mvn; that's mvn on the command line by itself.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process.

DecimalFormat.parse(String) stops at the first unparsable character and
drops the rest, so the locale numeric converters accepted trailing
garbage (123abc -> 123, '42 OR 1=1' -> 42). Every numeric locale
converter routes through DecimalLocaleConverter.parse, while the sibling
DateLocaleConverter already rejects leftover input via a ParsePosition
check. Switch to the same form and throw ParseException unless the whole
string is consumed.

Port of the 2.x fix to the 1.X branch. Updates the now-stale (B)
assertions across the numeric locale converter tests, which pinned the
old partial-parse values and now fall through to the converter default.
@garydgregory garydgregory changed the title reject trailing characters in DecimalLocaleConverter.parse (1.X) Reject trailing characters in DecimalLocaleConverter.parse (1.X) Jun 21, 2026
@garydgregory garydgregory merged commit 8b1586a into apache:1.X Jun 21, 2026
8 checks passed
@garydgregory

Copy link
Copy Markdown
Member

Thank you @rootvector2 , merged 🚀

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.

2 participants