You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@struts.apache.org by "lukaszlenart (via GitHub)" <gi...@apache.org> on 2026/10/17 07:42:56 UTC
[PR] WW-3666 Trim surrounding whitespace before converting to non-String types [struts]
lukaszlenart opened a new pull request, #2039:
URL: https://github.com/apache/struts/pull/2039
Fixes [WW-3666](https://issues.apache.org/jira/browse/WW-3666)
## Summary
Request values with surrounding whitespace (`" 42 "`, `" ACTIVE "`, `"\t2001-01-10\n"`) were rejected by most built-in converters. Only primitive `int`/`long` already trimmed, so `long` and `Long` disagreed on the same input. `Boolean` and `Character` silently misread padded input, with no conversion error.
`XWorkBasicConverter.convertValue` now trims `String` and `String[]` values before converting to a non-String scalar target:
- numbers (boxed, `double`/`float`, `BigInteger`, `BigDecimal`), enums, booleans, `Date`/`java.time`, `Class`
- arrays and collections are not trimmed at the entry; their elements re-enter `convertValue` and are trimmed per element
- `String`/`Object` targets keep the value untouched (they return before the trim), and so do `List<String>` elements
- a converter registered for a type still receives the raw value — it is looked up before the default converter
- `Character`/`char`: `" x"` → `'x'`; whitespace-only input keeps its first character (`" "` → `' '`), preserving the existing `testConvertChar` behaviour
Whitespace-only input now follows the existing `""` path.
Point 3 of the ticket ("errors should bubble up") is already covered: conversion failures are recorded and `ConversionErrorInterceptor` turns them into field errors.
## Behaviour changes worth a migration note (7.5.0)
| Input | Target | Before | After |
|---|---|---|---|
| `" true "` | `Boolean` / `boolean` | `false` | `true` |
| `" x"` | `Character` / `char` | `' '` | `'x'` |
| `""` or `" "` | `Boolean` | `false` | `null` |
| `" "` | boxed numbers, enums, `java.time` | conversion error | `null` (a `required` validator now reports it instead) |
| `" 42 "` etc. | boxed numbers, enums, `java.time`, arrays | conversion error | converted value |
Unchanged: `" "` into `int`/`long` is still a conversion error. `" "` into `double`/`float` gives `null`, which is what `""` already gives there (a pre-existing quirk in `NumberConverter.convertToDouble`/`convertToFloat`, left alone).
## Test plan
- [x] New `XWorkConverterTest` cases for numbers, enums, booleans, characters, `java.time`, `String[]` → `Long[]`, whitespace-only boxed → `null`, integral primitives → conversion error — the behaviour cases watched failing before the change
- [x] Guard cases (`String`/`Object`/`String[]` targets untouched, custom converter receives the raw value) checked by mutation: trimming before the early return, or in `XWorkConverter` before the lookup, fails them (and the existing `testConvertChar`)
- [x] `./mvnw test -DskipAssembly -pl core` — 3520 tests, 0 failures
- [x] `./mvnw test -DskipAssembly -DskipITs` (full reactor) — 4860 tests, 0 failures
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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: notifications-unsubscribe@struts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] WW-3666 Trim surrounding whitespace before converting to non-String types [struts]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #2039:
URL: https://github.com/apache/struts/pull/2039#issuecomment-6231376842
## [](https://sonarcloud.io/dashboard?id=apache_struts&pullRequest=2039) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_struts&pullRequest=2039&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_struts&pullRequest=2039&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_struts&pullRequest=2039&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [96.9% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_struts&pullRequest=2039&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_struts&pullRequest=2039&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_struts&pullRequest=2039)
--
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: notifications-unsubscribe@struts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] WW-3666 Trim surrounding whitespace before converting to non-String types [struts]
Posted by "lukaszlenart (via GitHub)" <gi...@apache.org>.
lukaszlenart commented on code in PR #2039:
URL: https://github.com/apache/struts/pull/2039#discussion_r4302038794
##########
core/src/main/java/org/apache/struts2/conversion/impl/XWorkBasicConverter.java:
##########
@@ -83,6 +84,8 @@ public Object convertValue(Map<String, Object> context, Object o, Member member,
return value;
}
+ value = trimSurroundingWhitespace(value, toType);
Review Comment:
Reassigning to method parameter is a bad idea
--
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: notifications-unsubscribe@struts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] WW-3666 Trim surrounding whitespace before converting to non-String types [struts]
Posted by "lukaszlenart (via GitHub)" <gi...@apache.org>.
lukaszlenart merged PR #2039:
URL: https://github.com/apache/struts/pull/2039
--
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: notifications-unsubscribe@struts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] WW-3666 Trim surrounding whitespace before converting to non-String types [struts]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #2039:
URL: https://github.com/apache/struts/pull/2039#issuecomment-6231767236
## [](https://sonarcloud.io/dashboard?id=apache_struts&pullRequest=2039) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_struts&pullRequest=2039&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_struts&pullRequest=2039&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_struts&pullRequest=2039&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [95.3% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_struts&pullRequest=2039&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_struts&pullRequest=2039&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_struts&pullRequest=2039)
--
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: notifications-unsubscribe@struts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org