struts git commit: WW-4628: proper decoding of parameters in query-string
Repository: struts Updated Branches: refs/heads/master 7fdc103e8 -> ef9c66118 WW-4628: proper decoding of parameters in query-string Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/ef9c6611 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/ef9c6611 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/ef9c6611 Branch: refs/heads/master Commit: ef9c66118ede16f3ff239ea864641d5bdadeecae Parents: 7fdc103 Author: cnenning Authored: Wed Aug 3 13:02:16 2016 +0200 Committer: cnenning Committed: Wed Aug 3 13:02:16 2016 +0200 -- .../org/apache/struts2/util/URLDecoderUtil.java | 12 .../struts2/views/util/DefaultUrlHelper.java| 27 +--- .../apache/struts2/util/URLDecoderUtilTest.java | 7 ++ .../views/util/DefaultUrlHelperTest.java| 71 +--- 4 files changed, 53 insertions(+), 64 deletions(-) -- http://git-wip-us.apache.org/repos/asf/struts/blob/ef9c6611/core/src/main/java/org/apache/struts2/util/URLDecoderUtil.java -- diff --git a/core/src/main/java/org/apache/struts2/util/URLDecoderUtil.java b/core/src/main/java/org/apache/struts2/util/URLDecoderUtil.java index 10f2a78..3c61d1e 100644 --- a/core/src/main/java/org/apache/struts2/util/URLDecoderUtil.java +++ b/core/src/main/java/org/apache/struts2/util/URLDecoderUtil.java @@ -19,4 +19,16 @@ public class URLDecoderUtil { return UDecoder.URLDecode(sequence, charset); } +/** + * Decodes a x-www-form-urlencoded string. + * @param sequence the String to decode + * @param charset The name of a supported character encoding. + * @param isQueryString whether input is a query string. If true other decoding rules apply. + * @return the newly decoded String + * @exception IllegalArgumentException If the encoding is not valid + */ +public static String decode(String sequence, String charset, boolean isQueryString) { +return UDecoder.URLDecode(sequence, charset, isQueryString); +} + } http://git-wip-us.apache.org/repos/asf/struts/blob/ef9c6611/core/src/main/java/org/apache/struts2/views/util/DefaultUrlHelper.java -- diff --git a/core/src/main/java/org/apache/struts2/views/util/DefaultUrlHelper.java b/core/src/main/java/org/apache/struts2/views/util/DefaultUrlHelper.java index 16739af..668d1a9 100644 --- a/core/src/main/java/org/apache/struts2/views/util/DefaultUrlHelper.java +++ b/core/src/main/java/org/apache/struts2/views/util/DefaultUrlHelper.java @@ -284,14 +284,25 @@ public class DefaultUrlHelper implements UrlHelper { * @return the encoded string */ public String decode( String input ) { - try { -return URLDecoderUtil.decode(input, encoding); - } catch (Exception e) { - LOG.warn("Could not decode URL parameter '{}', returning value un-decoded", input); - return input; - } +return URLDecoderUtil.decode(input, encoding, false); } +/** + * Decodes the URL using {@link URLDecoderUtil#decode(String, String, boolean)} with the encoding specified in the configuration. + * + * @param input the input to decode + * @param isQueryString whether input is a query string. If true other decoding rules apply. + * @return the encoded string + */ +public String decode( String input, boolean isQueryString ) { +try { +return URLDecoderUtil.decode(input, encoding, isQueryString); +} catch (Exception e) { +LOG.warn("Could not decode URL parameter '{}', returning value un-decoded", input); +return input; +} +} + public Map parseQueryString(String queryString, boolean forceValueArray) { Map queryParams = new LinkedHashMap(); if (queryString != null) { @@ -308,8 +319,8 @@ public class DefaultUrlHelper implements UrlHelper { paramValue = tmpParams[1]; } if (paramName != null) { -paramName = decode(paramName); -String translatedParamValue = decode(paramValue); +paramName = decode(paramName, true); +String translatedParamValue = decode(paramValue, true); if (queryParams.containsKey(paramName) || forceValueArray) { // WW-1619 append new param value to existing value(s) http://git-wip-us.apache.org/repos/asf/struts/blob/ef9c6611/core/src/test/java/org/apache/struts2/util/URLDecoderUtilTest.java -- diff -
struts git commit: merged fix for WW-4628 (proper url decoding of query-string)
Repository: struts Updated Branches: refs/heads/support-2-3 83bb64f4c -> 7d8c3598e merged fix for WW-4628 (proper url decoding of query-string) Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/7d8c3598 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/7d8c3598 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/7d8c3598 Branch: refs/heads/support-2-3 Commit: 7d8c3598ef4a4699515a2b8e1064d4e9b921a58b Parents: 83bb64f Author: cnenning Authored: Wed Aug 3 13:02:16 2016 +0200 Committer: cnenning Committed: Wed Aug 3 13:28:00 2016 +0200 -- .../org/apache/struts2/util/URLDecoderUtil.java | 12 .../struts2/views/util/DefaultUrlHelper.java| 22 +- .../apache/struts2/util/URLDecoderUtilTest.java | 7 ++ .../views/util/DefaultUrlHelperTest.java| 71 +--- 4 files changed, 53 insertions(+), 59 deletions(-) -- http://git-wip-us.apache.org/repos/asf/struts/blob/7d8c3598/core/src/main/java/org/apache/struts2/util/URLDecoderUtil.java -- diff --git a/core/src/main/java/org/apache/struts2/util/URLDecoderUtil.java b/core/src/main/java/org/apache/struts2/util/URLDecoderUtil.java index 10f2a78..3c61d1e 100644 --- a/core/src/main/java/org/apache/struts2/util/URLDecoderUtil.java +++ b/core/src/main/java/org/apache/struts2/util/URLDecoderUtil.java @@ -19,4 +19,16 @@ public class URLDecoderUtil { return UDecoder.URLDecode(sequence, charset); } +/** + * Decodes a x-www-form-urlencoded string. + * @param sequence the String to decode + * @param charset The name of a supported character encoding. + * @param isQueryString whether input is a query string. If true other decoding rules apply. + * @return the newly decoded String + * @exception IllegalArgumentException If the encoding is not valid + */ +public static String decode(String sequence, String charset, boolean isQueryString) { +return UDecoder.URLDecode(sequence, charset, isQueryString); +} + } http://git-wip-us.apache.org/repos/asf/struts/blob/7d8c3598/core/src/main/java/org/apache/struts2/views/util/DefaultUrlHelper.java -- diff --git a/core/src/main/java/org/apache/struts2/views/util/DefaultUrlHelper.java b/core/src/main/java/org/apache/struts2/views/util/DefaultUrlHelper.java index 8aacf63..153b240 100644 --- a/core/src/main/java/org/apache/struts2/views/util/DefaultUrlHelper.java +++ b/core/src/main/java/org/apache/struts2/views/util/DefaultUrlHelper.java @@ -299,7 +299,7 @@ public class DefaultUrlHelper implements UrlHelper { */ public String decode( String input ) { try { - return URLDecoderUtil.decode(input, encoding); + return URLDecoderUtil.decode(input, encoding, false); } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn("Could not decode URL parameter '#0', returning value un-decoded", input); @@ -308,6 +308,22 @@ public class DefaultUrlHelper implements UrlHelper { } } +/** + * Decodes the URL using {@link URLDecoderUtil#decode(String, String, boolean)} with the encoding specified in the configuration. + * + * @param input the input to decode + * @param isQueryString whether input is a query string. If true other decoding rules apply. + * @return the encoded string + */ +public String decode( String input, boolean isQueryString ) { +try { +return URLDecoderUtil.decode(input, encoding, isQueryString); +} catch (Exception e) { +LOG.warn("Could not decode URL parameter '{}', returning value un-decoded", input); +return input; +} +} + public Map parseQueryString(String queryString, boolean forceValueArray) { Map queryParams = new LinkedHashMap(); if (queryString != null) { @@ -324,8 +340,8 @@ public class DefaultUrlHelper implements UrlHelper { paramValue = tmpParams[1]; } if (paramName != null) { -paramName = decode(paramName); -String translatedParamValue = decode(paramValue); +paramName = decode(paramName, true); +String translatedParamValue = decode(paramValue, true); if (queryParams.containsKey(paramName) || forceValueArray) { // WW-1619 append new param value to existing value(s) http://git-wip-us.apache.org/repos/asf/struts/blob/7d8c3598/core/src/test/java/org/apache/struts2/uti