[
https://issues.apache.org/jira/browse/WW-5871?focusedWorklogId=1056504&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1056504
]
ASF GitHub Bot logged work on WW-5871:
--------------------------------------
Author: ASF GitHub Bot
Created on: 22/Nov/26 13:50
Start Date: 22/Nov/26 13:50
Worklog Time Spent: 10m
Work Description: lukaszlenart opened a new pull request, #2154:
URL: https://github.com/apache/struts/pull/2154
Fixes [WW-5871](https://issues.apache.org/jira/browse/WW-5871)
## Problem
Since 7.5.0, a request parameter bound to a `String` property loses its
leading and trailing whitespace, although WW-3666 (#2039) only meant to trim
before conversion to non-String types. A user reported it on the user list: a
password that starts or ends with a space stops matching after the upgrade.
A request parameter reaches `XWorkBasicConverter.convertValue` as a
`String[]`. The early return only skips values whose class already matches the
target type, so a `String[]` passes it. `trimSurroundingWhitespace` excluded
arrays, collections and `Character`, but not `String`, so it trimmed every
element before the conversion to `String`. The WW-3666 test covered only a bare
`String`, which takes the early return and never reaches the trim.
## Fix
The trim is skipped for every target `String` is assignable to
(`toType.isAssignableFrom(String.class)`). That covers `String` and also
`CharSequence`, `Comparable`, `Constable`. Those three fell through to the
first-element recursion with the already trimmed element, which 7.4.0 did not
do.
| input | target | 7.4.0 | 7.5.0 | this PR |
|---|---|---|---|---|
| `String[]{" summer2026 "}` | `String` | `" summer2026 "` | `"summer2026"`
| `" summer2026 "` |
| `String[]{" summer2026 "}` | `CharSequence` | `" summer2026 "` |
`"summer2026"` | `" summer2026 "` |
| `String[]{" 42 "}` | `Integer` | conversion error | `42` | `42`
(unchanged) |
Numbers, enums, `Boolean`, `java.time` and `Class` targets keep the WW-3666
trim.
## Testing
- New test `testRequestParameterBoundToStringKeepsSurroundingWhitespace`
with the reporter's example; fails before the fix.
- `mvn test -DskipAssembly -pl core`: 3801 tests, 0 failures.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Issue Time Tracking
-------------------
Worklog Id: (was: 1056504)
Remaining Estimate: 0h
Time Spent: 10m
> Request parameters bound to String properties are trimmed since 7.5.0
> ---------------------------------------------------------------------
>
> Key: WW-5871
> URL: https://issues.apache.org/jira/browse/WW-5871
> Project: Struts 2
> Issue Type: Bug
> Components: Core
> Affects Versions: 7.5.0
> Reporter: Lukasz Lenart
> Priority: Major
> Fix For: 7.6.0
>
> Time Spent: 10m
> Remaining Estimate: 0h
>
> WW-3666 trims surrounding whitespace before converting a value to a
> non-String type, and String targets are meant to keep the raw value. Since
> 7.5.0, however, a request parameter bound to a String property is trimmed too.
> A request parameter reaches {{XWorkBasicConverter.convertValue}} as a
> {{String[]}}. The early return skips conversion only when the value's class
> already matches the target type, so a {{String[]}} passes it. The trim step
> then trims every element, because it excludes arrays, collections and
> Character targets but not String, and the trimmed element is converted to
> String.
> {code:java}
> converter.convertValue(context, null, null, null, new String[]{" summer2026
> "}, String.class);
> // 7.4.0: " summer2026 "
> // 7.5.0: "summer2026"
> converter.convertValue(context, null, null, null, " summer2026 ",
> String.class);
> // " summer2026 " on both - the early return covers a bare String
> {code}
> The test added with WW-3666 covers only the bare String case, which never
> reaches the trim.
> Impact: any String property loses leading and trailing whitespace, for
> example a password that starts or ends with a space no longer matches after
> the upgrade.
> Reported on the user list.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)