Author: markt Date: Tue May 2 08:45:30 2017 New Revision: 1793437 URL: http://svn.apache.org/viewvc?rev=1793437&view=rev Log: Move towards using Charset rather than String internally to reduce the number of calls required to B2CConverter.getCharset() during a request.
Added: tomcat/trunk/java/org/apache/tomcat/util/digester/LocalStrings.properties (with props) Modified: tomcat/trunk/java/org/apache/catalina/connector/Request.java tomcat/trunk/java/org/apache/catalina/core/ApplicationServletRegistration.java tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java tomcat/trunk/java/org/apache/tomcat/util/buf/UDecoder.java tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FilterMap.java tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/JspPropertyGroup.java tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/LocalStrings.properties tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/SecurityCollection.java tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/SecurityConstraint.java tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/XmlEncodingBase.java tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java tomcat/trunk/java/org/apache/tomcat/util/digester/DocumentProperties.java tomcat/trunk/test/org/apache/catalina/core/TestApplicationContextGetRequestDispatcher.java tomcat/trunk/test/org/apache/tomcat/util/buf/TestUDecoder.java Modified: tomcat/trunk/java/org/apache/catalina/connector/Request.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Request.java?rev=1793437&r1=1793436&r2=1793437&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/connector/Request.java (original) +++ tomcat/trunk/java/org/apache/catalina/connector/Request.java Tue May 2 08:45:30 2017 @@ -2027,7 +2027,7 @@ public class Request implements HttpServ candidate = uri.substring(0, pos); } candidate = removePathParameters(candidate); - candidate = UDecoder.URLDecode(candidate, connector.getURIEncoding()); + candidate = UDecoder.URLDecode(candidate, connector.getURICharset()); candidate = org.apache.tomcat.util.http.RequestUtil.normalize(candidate); boolean match = canonicalContextPath.equals(candidate); while (!match && pos != -1) { @@ -2038,7 +2038,7 @@ public class Request implements HttpServ candidate = uri.substring(0, pos); } candidate = removePathParameters(candidate); - candidate = UDecoder.URLDecode(candidate, connector.getURIEncoding()); + candidate = UDecoder.URLDecode(candidate, connector.getURICharset()); candidate = org.apache.tomcat.util.http.RequestUtil.normalize(candidate); match = canonicalContextPath.equals(candidate); } Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationServletRegistration.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationServletRegistration.java?rev=1793437&r1=1793436&r2=1793437&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/ApplicationServletRegistration.java (original) +++ tomcat/trunk/java/org/apache/catalina/core/ApplicationServletRegistration.java Tue May 2 08:45:30 2017 @@ -17,6 +17,7 @@ package org.apache.catalina.core; +import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -191,7 +192,7 @@ public class ApplicationServletRegistrat for (String urlPattern : urlPatterns) { context.addServletMappingDecoded( - UDecoder.URLDecode(urlPattern, "UTF-8"), wrapper.getName()); + UDecoder.URLDecode(urlPattern, StandardCharsets.UTF_8), wrapper.getName()); } return Collections.emptySet(); } Modified: tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java?rev=1793437&r1=1793436&r2=1793437&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java (original) +++ tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java Tue May 2 08:45:30 2017 @@ -1524,7 +1524,7 @@ public class WebdavServlet } // Remove url encoding from destination - destinationPath = UDecoder.URLDecode(destinationPath, "UTF8"); + destinationPath = UDecoder.URLDecode(destinationPath, StandardCharsets.UTF_8); int protocolIndex = destinationPath.indexOf("://"); if (protocolIndex >= 0) { 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=1793437&r1=1793436&r2=1793437&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/buf/UDecoder.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/buf/UDecoder.java Tue May 2 08:45:30 2017 @@ -19,6 +19,7 @@ package org.apache.tomcat.util.buf; import java.io.CharConversionException; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import org.apache.juli.logging.Log; @@ -294,7 +295,7 @@ public final class UDecoder { /** * Decode and return the specified URL-encoded String. - * When the byte array is converted to a string, the UTF-8 is used. This may + * When the byte array is converted to a string, UTF-8 is used. This may * be different than some other servers. It is assumed the string is not a * query string. * @@ -304,7 +305,7 @@ public final class UDecoder { * by a valid 2-digit hexadecimal number */ public static String URLDecode(String str) { - return URLDecode(str, null); + return URLDecode(str, StandardCharsets.UTF_8); } @@ -318,13 +319,34 @@ public final class UDecoder { * @return the decoded string * @exception IllegalArgumentException if a '%' character is not followed * by a valid 2-digit hexadecimal number + * + * @deprecated This method will be removed in Tomcat 9 */ + @Deprecated public static String URLDecode(String str, String enc) { return URLDecode(str, enc, false); } /** + * Decode and return the specified URL-encoded String. It is assumed the + * string is not a query string. + * + * @param str The url-encoded string + * @param charset The character encoding to use; if null, UTF-8 is used. + * @return the decoded string + * @exception IllegalArgumentException if a '%' character is not followed + * by a valid 2-digit hexadecimal number + */ + public static String URLDecode(String str, Charset charset) { + if (str == null) { + return null; + } + return URLDecode(str.getBytes(StandardCharsets.US_ASCII), charset, false); + } + + + /** * Decode and return the specified URL-encoded String. * * @param str The url-encoded string @@ -334,7 +356,10 @@ public final class UDecoder { * @return the decoded string * @exception IllegalArgumentException if a '%' character is not followed * by a valid 2-digit hexadecimal number + * + * @deprecated This method will be removed in Tomcat 9 */ + @Deprecated public static String URLDecode(String str, String enc, boolean isQuery) { if (str == null) { return null; @@ -357,11 +382,36 @@ public final class UDecoder { * @return the decoded string * @exception IllegalArgumentException if a '%' character is not followed * by a valid 2-digit hexadecimal number + * + * @deprecated This method will be removed in Tomcat 9 */ + @Deprecated public static String URLDecode(byte[] bytes, String enc, boolean isQuery) { + Charset charset = null; + + if (enc != null) { + try { + charset = B2CConverter.getCharset(enc); + } catch (UnsupportedEncodingException uee) { + if (log.isDebugEnabled()) { + log.debug(sm.getString("uDecoder.urlDecode.uee", enc), uee); + } + } + } - if (bytes == null) + return URLDecode(bytes, charset, isQuery); + } + + + private static String URLDecode(byte[] bytes, Charset charset, boolean isQuery) { + + if (bytes == null) { return null; + } + + if (charset == null) { + charset = StandardCharsets.UTF_8; + } int len = bytes.length; int ix = 0; @@ -380,18 +430,8 @@ public final class UDecoder { } bytes[ox++] = b; } - if (enc != null) { - try { - return new String(bytes, 0, ox, B2CConverter.getCharset(enc)); - } catch (UnsupportedEncodingException uee) { - if (log.isDebugEnabled()) { - log.debug(sm.getString("uDecoder.urlDecode.uee", enc), uee); - } - return null; - } - } - return new String(bytes, 0, ox, StandardCharsets.UTF_8); + return new String(bytes, 0, ox, charset); } Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FilterMap.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FilterMap.java?rev=1793437&r1=1793436&r2=1793437&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FilterMap.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FilterMap.java Tue May 2 08:45:30 2017 @@ -127,7 +127,7 @@ public class FilterMap extends XmlEncodi } public void addURLPattern(String urlPattern) { - addURLPatternDecoded(UDecoder.URLDecode(urlPattern, getEncoding())); + addURLPatternDecoded(UDecoder.URLDecode(urlPattern, getCharset())); } public void addURLPatternDecoded(String urlPattern) { if ("*".equals(urlPattern)) { Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/JspPropertyGroup.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/JspPropertyGroup.java?rev=1793437&r1=1793436&r2=1793437&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/JspPropertyGroup.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/JspPropertyGroup.java Tue May 2 08:45:30 2017 @@ -78,7 +78,7 @@ public class JspPropertyGroup extends Xm private LinkedHashSet<String> urlPattern = new LinkedHashSet<>(); public void addUrlPattern(String urlPattern) { - addUrlPatternDecoded(UDecoder.URLDecode(urlPattern, getEncoding())); + addUrlPatternDecoded(UDecoder.URLDecode(urlPattern, getCharset())); } public void addUrlPatternDecoded(String urlPattern) { this.urlPattern.add(urlPattern); Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/LocalStrings.properties?rev=1793437&r1=1793436&r2=1793437&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/LocalStrings.properties (original) +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/LocalStrings.properties Tue May 2 08:45:30 2017 @@ -62,3 +62,5 @@ webXml.wrongFragmentName=Used a wrong fr webXmlParser.applicationParse=Parse error in application web.xml file at [{0}] webXmlParser.applicationPosition=Occurred at line [{0}] column [{1}] webXmlParser.applicationStart=Parsing application web.xml file at [{0}] + +xmlEncodingBase.encodingInvalid=The encoding [{0}] is not recognised by this JRE. The existing value of [{1}] will be used \ No newline at end of file Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/SecurityCollection.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/SecurityCollection.java?rev=1793437&r1=1793436&r2=1793437&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/SecurityCollection.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/SecurityCollection.java Tue May 2 08:45:30 2017 @@ -17,6 +17,7 @@ package org.apache.tomcat.util.descriptor.web; import java.io.Serializable; +import java.nio.charset.StandardCharsets; import org.apache.tomcat.util.buf.UDecoder; @@ -209,7 +210,7 @@ public class SecurityCollection extends * @param pattern The pattern */ public void addPattern(String pattern) { - addPatternDecoded(UDecoder.URLDecode(pattern, "UTF-8")); + addPatternDecoded(UDecoder.URLDecode(pattern, StandardCharsets.UTF_8)); } public void addPatternDecoded(String pattern) { Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/SecurityConstraint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/SecurityConstraint.java?rev=1793437&r1=1793436&r2=1793437&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/SecurityConstraint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/SecurityConstraint.java Tue May 2 08:45:30 2017 @@ -281,7 +281,7 @@ public class SecurityConstraint extends if (collection == null) return; - collection.setEncoding(getEncoding()); + collection.setCharset(getCharset()); SecurityCollection results[] = new SecurityCollection[collections.length + 1]; Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java?rev=1793437&r1=1793436&r2=1793437&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/WebXml.java Tue May 2 08:45:30 2017 @@ -55,7 +55,9 @@ import org.apache.tomcat.util.res.String * This class checks for invalid duplicates (eg filter/servlet names) * StandardContext will check validity of values (eg URL formats etc) */ -public class WebXml extends XmlEncodingBase implements DocumentProperties.Encoding { +@SuppressWarnings("deprecation") +public class WebXml extends XmlEncodingBase implements DocumentProperties.Encoding, + DocumentProperties.Charset { protected static final String ORDER_OTHERS = "org.apache.catalina.order.others"; @@ -318,7 +320,7 @@ public class WebXml extends XmlEncodingB private final Map<String,String> servletMappings = new HashMap<>(); private final Set<String> servletMappingNames = new HashSet<>(); public void addServletMapping(String urlPattern, String servletName) { - addServletMappingDecoded(UDecoder.URLDecode(urlPattern, getEncoding()), servletName); + addServletMappingDecoded(UDecoder.URLDecode(urlPattern, getCharset()), servletName); } public void addServletMappingDecoded(String urlPattern, String servletName) { String oldServletName = servletMappings.put(urlPattern, servletName); @@ -403,7 +405,7 @@ public class WebXml extends XmlEncodingB // jsp-config/jsp-property-group private final Set<JspPropertyGroup> jspPropertyGroups = new LinkedHashSet<>(); public void addJspPropertyGroup(JspPropertyGroup propertyGroup) { - propertyGroup.setEncoding(getEncoding()); + propertyGroup.setCharset(getCharset()); jspPropertyGroups.add(propertyGroup); } public Set<JspPropertyGroup> getJspPropertyGroups() { @@ -415,7 +417,7 @@ public class WebXml extends XmlEncodingB // TODO: Should support multiple description elements with language private final Set<SecurityConstraint> securityConstraints = new HashSet<>(); public void addSecurityConstraint(SecurityConstraint securityConstraint) { - securityConstraint.setEncoding(getEncoding()); + securityConstraint.setCharset(getCharset()); securityConstraints.add(securityConstraint); } public Set<SecurityConstraint> getSecurityConstraints() { Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/XmlEncodingBase.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/XmlEncodingBase.java?rev=1793437&r1=1793436&r2=1793437&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/XmlEncodingBase.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/XmlEncodingBase.java Tue May 2 08:45:30 2017 @@ -16,17 +16,38 @@ */ package org.apache.tomcat.util.descriptor.web; +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +import org.apache.juli.logging.Log; +import org.apache.juli.logging.LogFactory; +import org.apache.tomcat.util.buf.B2CConverter; +import org.apache.tomcat.util.res.StringManager; + /** * Base class for those elements that need to track the encoding used in the * source XML. */ public abstract class XmlEncodingBase { - private String encoding = null; + private static final Log log = LogFactory.getLog(XmlEncodingBase.class); + private static final StringManager sm = StringManager.getManager(XmlEncodingBase.class); + private Charset charset = StandardCharsets.UTF_8; + /** + * @param encoding The encoding of the XML source that was used to + * populated this object. + * @deprecated This method will be removed in Tomcat 9 + */ + @Deprecated public void setEncoding(String encoding) { - this.encoding = encoding; + try { + charset = B2CConverter.getCharset(encoding); + } catch (UnsupportedEncodingException e) { + log.warn(sm.getString("xmlEncodingBase.encodingInvalid", encoding, charset.name()), e); + } } @@ -36,11 +57,27 @@ public abstract class XmlEncodingBase { * * @return The encoding of the associated XML source or <code>UTF-8</code> * if the encoding could not be determined + * @deprecated This method will be removed in Tomcat 9 */ + @Deprecated public String getEncoding() { - if (encoding == null || encoding.length() == 0) { - return "UTF-8"; - } - return encoding; + return charset.name(); + } + + + public void setCharset(Charset charset) { + this.charset = charset; + } + + + /** + * Obtain the character encoding of the XML source that was used to + * populated this object. + * + * @return The character encoding of the associated XML source or + * <code>UTF-8</code> if the encoding could not be determined + */ + public Charset getCharset() { + return charset; } } Modified: tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java?rev=1793437&r1=1793436&r2=1793437&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/digester/Digester.java Tue May 2 08:45:30 2017 @@ -20,6 +20,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.io.UnsupportedEncodingException; import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.net.URISyntaxException; @@ -39,6 +40,8 @@ import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.ExceptionUtils; import org.apache.tomcat.util.IntrospectionUtils; +import org.apache.tomcat.util.buf.B2CConverter; +import org.apache.tomcat.util.res.StringManager; import org.apache.tomcat.util.security.PermissionCheck; import org.xml.sax.Attributes; import org.xml.sax.EntityResolver; @@ -76,7 +79,6 @@ import org.xml.sax.helpers.AttributesImp */ public class Digester extends DefaultHandler2 { - // ---------------------------------------------------------- Static Fields protected static IntrospectionUtils.PropertySource propertySource = null; @@ -289,8 +291,8 @@ public class Digester extends DefaultHan /** * The Log to which most logging calls will be made. */ - protected Log log = LogFactory.getLog("org.apache.tomcat.util.digester.Digester"); - + protected Log log = LogFactory.getLog(Digester.class); + protected StringManager sm = StringManager.getManager(Digester.class); /** * The Log to which all SAX event related logging calls will be made. @@ -1112,6 +1114,7 @@ public class Digester extends DefaultHan * * @exception SAXException if a parsing error is to be reported */ + @SuppressWarnings("deprecation") @Override public void startDocument() throws SAXException { @@ -1119,8 +1122,17 @@ public class Digester extends DefaultHan saxLog.debug("startDocument()"); } - if (locator instanceof Locator2 && root instanceof DocumentProperties.Encoding) { - ((DocumentProperties.Encoding) root).setEncoding(((Locator2) locator).getEncoding()); + if (locator instanceof Locator2) { + if (root instanceof DocumentProperties.Charset) { + String enc = ((Locator2) locator).getEncoding(); + try { + ((DocumentProperties.Charset) root).setCharset(B2CConverter.getCharset(enc)); + } catch (UnsupportedEncodingException e) { + log.warn(sm.getString("disgester.encodingInvalid", enc), e); + } + } else if (root instanceof DocumentProperties.Encoding) { + ((DocumentProperties.Encoding) root).setEncoding(((Locator2) locator).getEncoding()); + } } // ensure that the digester is properly configured, as Modified: tomcat/trunk/java/org/apache/tomcat/util/digester/DocumentProperties.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/digester/DocumentProperties.java?rev=1793437&r1=1793436&r2=1793437&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/digester/DocumentProperties.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/digester/DocumentProperties.java Tue May 2 08:45:30 2017 @@ -26,9 +26,19 @@ package org.apache.tomcat.util.digester; public interface DocumentProperties { /** - * The encoding used by the source XMl document. + * The encoding used by the source XML document. + * + * @deprecated This method will be removed in Tomcat 9 */ + @Deprecated public interface Encoding { public void setEncoding(String encoding); } + + /** + * The character encoding used by the source XML document. + */ + public interface Charset { + public void setCharset(java.nio.charset.Charset charset); + } } Added: tomcat/trunk/java/org/apache/tomcat/util/digester/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/digester/LocalStrings.properties?rev=1793437&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/digester/LocalStrings.properties (added) +++ tomcat/trunk/java/org/apache/tomcat/util/digester/LocalStrings.properties Tue May 2 08:45:30 2017 @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +disgester.encodingInvalid=The encoding [{0}] is not recognised by the JRE and will be ignored \ No newline at end of file Propchange: tomcat/trunk/java/org/apache/tomcat/util/digester/LocalStrings.properties ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/test/org/apache/catalina/core/TestApplicationContextGetRequestDispatcher.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/core/TestApplicationContextGetRequestDispatcher.java?rev=1793437&r1=1793436&r2=1793437&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/core/TestApplicationContextGetRequestDispatcher.java (original) +++ tomcat/trunk/test/org/apache/catalina/core/TestApplicationContextGetRequestDispatcher.java Tue May 2 08:45:30 2017 @@ -17,6 +17,7 @@ package org.apache.catalina.core; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collection; @@ -369,7 +370,8 @@ public class TestApplicationContextGetRe // Add a target servlet to dispatch to Tomcat.addServlet(ctx, "target", new TargetServlet()); - ctx.addServletMappingDecoded(UDecoder.URLDecode(targetPath, "UTF-8"), "target"); + ctx.addServletMappingDecoded( + UDecoder.URLDecode(targetPath, StandardCharsets.UTF_8), "target"); if (useAsync) { Wrapper w = Tomcat.addServlet( @@ -378,7 +380,7 @@ public class TestApplicationContextGetRe } else { Tomcat.addServlet(ctx, "rd", new DispatcherServlet(dispatchPath)); } - ctx.addServletMappingDecoded(UDecoder.URLDecode(startPath, "UTF-8"), "rd"); + ctx.addServletMappingDecoded(UDecoder.URLDecode(startPath, StandardCharsets.UTF_8), "rd"); tomcat.start(); Modified: tomcat/trunk/test/org/apache/tomcat/util/buf/TestUDecoder.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/buf/TestUDecoder.java?rev=1793437&r1=1793436&r2=1793437&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/tomcat/util/buf/TestUDecoder.java (original) +++ tomcat/trunk/test/org/apache/tomcat/util/buf/TestUDecoder.java Tue May 2 08:45:30 2017 @@ -16,6 +16,8 @@ */ package org.apache.tomcat.util.buf; +import java.nio.charset.StandardCharsets; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -47,41 +49,41 @@ public class TestUDecoder { @Test public void testURLDecodeStringValidIso88591Start() { - String result = UDecoder.URLDecode("%41xxxx", "ISO-8859-1"); + String result = UDecoder.URLDecode("%41xxxx", StandardCharsets.ISO_8859_1); assertEquals("Axxxx", result); } @Test public void testURLDecodeStringValidIso88591Middle() { - String result = UDecoder.URLDecode("xx%41xx", "ISO-8859-1"); + String result = UDecoder.URLDecode("xx%41xx", StandardCharsets.ISO_8859_1); assertEquals("xxAxx", result); } @Test public void testURLDecodeStringValidIso88591End() { - String result = UDecoder.URLDecode("xxxx%41", "ISO-8859-1"); + String result = UDecoder.URLDecode("xxxx%41", StandardCharsets.ISO_8859_1); assertEquals("xxxxA", result); } @Test public void testURLDecodeStringValidUtf8Start() { - String result = UDecoder.URLDecode("%c3%aaxxxx", "UTF-8"); + String result = UDecoder.URLDecode("%c3%aaxxxx", StandardCharsets.UTF_8); assertEquals("\u00eaxxxx", result); } @Test public void testURLDecodeStringValidUtf8Middle() { - String result = UDecoder.URLDecode("xx%c3%aaxx", "UTF-8"); + String result = UDecoder.URLDecode("xx%c3%aaxx", StandardCharsets.UTF_8); assertEquals("xx\u00eaxx", result); } @Test public void testURLDecodeStringValidUtf8End() { - String result = UDecoder.URLDecode("xxxx%c3%aa", "UTF-8"); + String result = UDecoder.URLDecode("xxxx%c3%aa", StandardCharsets.UTF_8); assertEquals("xxxx\u00ea", result); } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org