Author: markt
Date: Fri Apr 28 19:29:42 2017
New Revision: 1793136
URL: http://svn.apache.org/viewvc?rev=1793136&view=rev
Log:
Code review while investigating expanding the use of Charset for encoding
rather than String.
URLs (when %nn encoded) should always be in US-ASCII. Simplify the decode
method on that basis.
Modified:
tomcat/trunk/java/org/apache/tomcat/util/buf/UDecoder.java
Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/UDecoder.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/UDecoder.java?rev=1793136&r1=1793135&r2=1793136&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/buf/UDecoder.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/buf/UDecoder.java Fri Apr 28
19:29:42 2017
@@ -328,7 +328,7 @@ public final class UDecoder {
* Decode and return the specified URL-encoded String.
*
* @param str The url-encoded string
- * @param enc The encoding to use; if null, the default encoding is used.
If
+ * @param enc The encoding to use; if null, ISO-8859-1 is used. If
* an unsupported encoding is specified null will be returned
* @param isQuery Is this a query string being processed
* @return the decoded string
@@ -336,28 +336,19 @@ public final class UDecoder {
* by a valid 2-digit hexadecimal number
*/
public static String URLDecode(String str, String enc, boolean isQuery) {
- if (str == null)
- return (null);
+ if (str == null) {
+ return null;
+ }
+
+ // URLs are always in US-ASCII
+ byte[] bytes = str.getBytes(StandardCharsets.US_ASCII);
- // use the specified encoding to extract bytes out of the
- // given string so that the encoding is not lost. If an
- // encoding is not specified, use ISO-8859-1
- byte[] bytes = null;
- try {
- if (enc == null) {
- bytes = str.getBytes(StandardCharsets.ISO_8859_1);
- enc = "ISO-8859-1";
- } else {
- bytes = str.getBytes(B2CConverter.getCharset(enc));
- }
- } catch (UnsupportedEncodingException uee) {
- if (log.isDebugEnabled()) {
- log.debug(sm.getString("uDecoder.urlDecode.uee", enc), uee);
- }
+ // If an encoding is not specified, use ISO-8859-1
+ if (enc == null) {
+ enc = "ISO-8859-1";
}
return URLDecode(bytes, enc, isQuery);
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]