This is an automated email from the ASF dual-hosted git repository.
lukaszlenart pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/struts.git
The following commit(s) were added to refs/heads/main by this push:
new 5217461a0 WW-5871 fix(core): keep request parameters bound to String
untrimmed (#2154)
5217461a0 is described below
commit 5217461a0f2f500ce65f5e8dfb2e4310e29396e0
Author: Lukasz Lenart <[email protected]>
AuthorDate: Sun Nov 22 15:03:07 2026 +0100
WW-5871 fix(core): keep request parameters bound to String untrimmed (#2154)
WW-3666 trims input before converting it to a non-String type, but
trimSurroundingWhitespace only excluded arrays, collections and
Character. A request parameter arrives as String[], which passes the
early return for a String target, so every element was trimmed before
it was converted to String: " summer2026 " became "summer2026".
The trim is now skipped for String and every type String is assignable
to (CharSequence, Comparable, ...), restoring the 7.4.0 value.
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../java/org/apache/struts2/conversion/impl/XWorkBasicConverter.java | 2 +-
.../java/org/apache/struts2/conversion/impl/XWorkConverterTest.java | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git
a/core/src/main/java/org/apache/struts2/conversion/impl/XWorkBasicConverter.java
b/core/src/main/java/org/apache/struts2/conversion/impl/XWorkBasicConverter.java
index db37cea9b..7a5b0e005 100644
---
a/core/src/main/java/org/apache/struts2/conversion/impl/XWorkBasicConverter.java
+++
b/core/src/main/java/org/apache/struts2/conversion/impl/XWorkBasicConverter.java
@@ -163,7 +163,7 @@ public class XWorkBasicConverter extends
DefaultTypeConverter {
}
private Object trimSurroundingWhitespace(Object value, Class toType) {
- if (toType.isArray() || Collection.class.isAssignableFrom(toType) ||
toType == Character.class || toType == char.class) {
+ if (toType.isAssignableFrom(String.class) || toType.isArray() ||
Collection.class.isAssignableFrom(toType) || toType == Character.class ||
toType == char.class) {
return value;
}
if (value instanceof String str) {
diff --git
a/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java
b/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java
index 93aeebc93..9d4d250e9 100644
---
a/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java
+++
b/core/src/test/java/org/apache/struts2/conversion/impl/XWorkConverterTest.java
@@ -799,6 +799,11 @@ public class XWorkConverterTest extends XWorkTestCase {
assertArrayEquals(new String[]{" keep "}, (String[])
converter.convertValue(context, null, null, null, new String[]{" keep "},
String[].class));
}
+ public void testRequestParameterBoundToStringKeepsSurroundingWhitespace() {
+ assertEquals(" summer2026 ", converter.convertValue(context, null,
null, null, new String[]{" summer2026 "}, String.class));
+ assertEquals(" summer2026 ", converter.convertValue(context, null,
null, null, new String[]{" summer2026 "}, CharSequence.class));
+ }
+
public void testCustomTypeConverterReceivesUntrimmedValue() {
XWorkConverter freshConverter = container.inject(XWorkConverter.class);
freshConverter.setTypeConverterHolder(new StrutsTypeConverterHolder());