You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2017/02/13 09:48:59 UTC
[1/3] struts git commit: [WW-4737] preserve nulls instead of
converting them to the string 'null'
Repository: struts
Updated Branches:
refs/heads/master 533b236fd -> 4b96958be
[WW-4737] preserve nulls instead of converting them to the string 'null'
- Also simplify if-else logic to be more readable and avoid double-negatives
Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/58667e64
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/58667e64
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/58667e64
Branch: refs/heads/master
Commit: 58667e64970c528461cf7c5835f9a253c969f737
Parents: 47a415a
Author: antuarc <ca...@dsiti.qld.gov.au>
Authored: Wed Feb 1 12:26:31 2017 +1000
Committer: antuarc <ca...@dsiti.qld.gov.au>
Committed: Wed Feb 1 12:26:31 2017 +1000
----------------------------------------------------------------------
.../org/apache/struts2/dispatcher/Parameter.java | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts/blob/58667e64/core/src/main/java/org/apache/struts2/dispatcher/Parameter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/Parameter.java b/core/src/main/java/org/apache/struts2/dispatcher/Parameter.java
index 30781a1..4e06ef6 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/Parameter.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/Parameter.java
@@ -1,5 +1,7 @@
package org.apache.struts2.dispatcher;
+import java.util.Objects;
+
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -42,23 +44,23 @@ public interface Parameter {
}
private String[] toStringArray() {
- if (value != null && value.getClass().isArray()) {
+ if (value == null) {
+ LOG.trace("The value is null, empty array of string will be returned!");
+ return new String[]{};
+ } else if (value.getClass().isArray()) {
LOG.trace("Converting value {} to array of strings", value);
Object[] values = (Object[]) value;
String[] strValues = new String[values.length];
int i = 0;
for (Object v : values) {
- strValues[i] = String.valueOf(v);
+ strValues[i] = Objects.toString(v, null);
i++;
}
return strValues;
- } else if (value != null) {
- LOG.trace("Converting value {} to simple string", value);
- return new String[]{ String.valueOf(value) };
} else {
- LOG.trace("The value is null, empty array of string will be returned!");
- return new String[]{};
+ LOG.trace("Converting value {} to simple string", value);
+ return new String[]{ value.toString() };
}
}
[3/3] struts git commit: WW-4737 Fixes issue with array of nulls
Posted by lu...@apache.org.
WW-4737 Fixes issue with array of nulls
Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/4b96958b
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/4b96958b
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/4b96958b
Branch: refs/heads/master
Commit: 4b96958be90b45e959ef600b89af33833d51eb27
Parents: 533b236 26bc9cd
Author: Lukasz Lenart <lu...@apache.org>
Authored: Mon Feb 13 10:48:52 2017 +0100
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Mon Feb 13 10:48:52 2017 +0100
----------------------------------------------------------------------
.../apache/struts2/dispatcher/Parameter.java | 16 +++++-----
.../struts2/dispatcher/ParameterTest.java | 32 ++++++++++++++++++++
2 files changed, 41 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
[2/3] struts git commit: [WW-4737] add unit testing for parameters
being converted to string arrays
Posted by lu...@apache.org.
[WW-4737] add unit testing for parameters being converted to string arrays
Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/26bc9cd6
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/26bc9cd6
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/26bc9cd6
Branch: refs/heads/master
Commit: 26bc9cd64bd9e69f7bf2e1076150806581c355f4
Parents: 58667e6
Author: antuarc <ca...@dsiti.qld.gov.au>
Authored: Wed Feb 1 12:27:02 2017 +1000
Committer: antuarc <ca...@dsiti.qld.gov.au>
Committed: Wed Feb 1 12:27:02 2017 +1000
----------------------------------------------------------------------
.../struts2/dispatcher/ParameterTest.java | 32 ++++++++++++++++++++
1 file changed, 32 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts/blob/26bc9cd6/core/src/test/java/org/apache/struts2/dispatcher/ParameterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/dispatcher/ParameterTest.java b/core/src/test/java/org/apache/struts2/dispatcher/ParameterTest.java
new file mode 100644
index 0000000..25d9409
--- /dev/null
+++ b/core/src/test/java/org/apache/struts2/dispatcher/ParameterTest.java
@@ -0,0 +1,32 @@
+package org.apache.struts2.dispatcher;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.*;
+
+public class ParameterTest {
+
+ private static final String PARAM_NAME = "param";
+
+ @DataProvider(name = "paramValues")
+ Object[][] paramValues() {
+ return new Object[][] {
+ {null, new String[0]},
+ {"input", new String[] {"input"}},
+ {Integer.valueOf(5), new String[] {"5"}},
+ {new String[] {"foo"}, new String[] {"foo"}},
+ {new Object[] {null}, new String[] {null}},
+ };
+ }
+
+ @Test(dataProvider = "paramValues")
+ public void shouldConvertRequestValuesToStringArrays(Object input, String[] expected) {
+ Parameter.Request request = new Parameter.Request(PARAM_NAME, input);
+
+ String[] result = request.getMultipleValues();
+
+ assertEquals(result, expected);
+ assertNotSame(result, input);
+ }
+}