sahvx655-wq opened a new pull request, #430:
URL: https://github.com/apache/commons-validator/pull/430

   Came at this from the other end: the German and French number validators 
were rejecting amounts the British one accepted, and the parse trace showed 
both the initial attempt and the lenient retry failing at the same index, which 
puts the fault in the fallback pattern rather than in the input.
   
   1. `CurrencyValidator.parse` and `PercentValidator.parse` rebuild the 
pattern with the symbol removed and re-parse, but they delete only the symbol 
character itself.
   2. `NumberFormat.getCurrencyInstance(Locale.GERMANY).toPattern()` is 
`#,##0.00 ¤` and `getPercentInstance(Locale.FRANCE).toPattern()` is `#,##0 %`, 
so what survives the rebuild is a mandatory non-breaking-space suffix.
   3. The retry then fails exactly where the first parse did, so 
`validate("1.234,56", Locale.GERMANY)` and `validate("12", Locale.FRANCE)` come 
back null, while the prefix-symbol locales such as en-GB are fine.
   4. The inverse is the worse half: a bare non-breaking space satisfies that 
leftover suffix on its own, so `validate("1.234,56 ", Locale.GERMANY)` yields 
1234.56 and `validate("12 ", Locale.FRANCE)` yields 0.12 with no symbol present 
at all.
   
   Both methods now drop the space adjacent to the symbol along with it. Left 
alone, the behaviour cuts both ways for every suffix-symbol locale (de, fr, it 
and the rest): correctly formatted amounts are silently refused, and a stray 
separator passes as a substitute for the currency or percent sign, which is a 
poor property in something callers lean on to reject malformed money. The two 
regression tests build an explicit suffix pattern instead of reading the JDK's 
locale data, so they will not drift with CLDR updates; both fail on master and 
pass with the change.
   
   Thanks for your contribution to [Apache 
Commons](https://commons.apache.org/)! Your help is appreciated!
   
   Before you push a pull request, review this list:
   
   - [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
   - [ ] Read the [ASF Generative Tooling 
Guidance](https://www.apache.org/legal/generative-tooling.html) 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?
   - [x] Run a successful build using the default 
[Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command 
line by itself.
   - [x] 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.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] 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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to