Bug 61452

Summary: java.io.UnsupportedEncodingException: UTF_8 when using WebDAV servlet
Product: Tomcat 7 Reporter: Maarten van Hulsentop <maarten>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 7.0.81   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: webdav webapps folder to ease reproduction

Description Maarten van Hulsentop 2017-08-24 13:49:36 UTC
When using the WebDAV servlet, the log shows java.io.UnsupportedEncodingException: UTF_8 exceptions on requests.

Reproduction steps;
- Download and unzip tomcat version 7.0.81
- Unzip the webdav.zip webdav in the root of the tomcat.
- Start the Tomcat server 
- Connect with anyclient to http://localhost:8080/webdav/
- See the stacktrace in the console.

java.io.UnsupportedEncodingException: UTF_8
        at sun.nio.cs.StreamEncoder.forOutputStreamWriter(StreamEncoder.java:61)
        at java.io.OutputStreamWriter.<init>(OutputStreamWriter.java:100)
        at org.apache.catalina.util.URLEncoder.encode(URLEncoder.java:170)
        at org.apache.catalina.servlets.WebdavServlet.rewriteUrl(WebdavServlet.java:444)
        at org.apache.catalina.servlets.WebdavServlet.parseProperties(WebdavServlet.java:2122)
        at org.apache.catalina.servlets.WebdavServlet.doPropfind(WebdavServlet.java:702)
<SNIP>

I have traced this to org.apache.catalina.servlets.WebdavServlet.rewriteUrl(String) . The implementation for tc7.x is;
  return URL_ENCODER_XML.encode(path, "UTF_8");
For tc8.5 it is;
  return URL_ENCODER_XML.encode(path, StandardCharsets.UTF_8);

I suspect that this is a pretty simple copy-paste error. The string should probably be changed from "UTF_8" (with underscore) to "UTF-8" (with a dash). But i have not tested this.
Comment 1 Maarten van Hulsentop 2017-08-24 13:51:43 UTC
Created attachment 35252 [details]
webdav webapps folder to ease reproduction
Comment 2 Mark Thomas 2017-08-24 23:29:09 UTC
Fixed in:
- 8.0.x for 8.0.47 onwards
- 7.0.x for 7.0.82 onwards

Thanks for the report. 8.0.x was affected too as were a couple of tests.