Bug 61452 - java.io.UnsupportedEncodingException: UTF_8 when using WebDAV servlet
Summary: java.io.UnsupportedEncodingException: UTF_8 when using WebDAV servlet
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 7.0.81
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-24 13:49 UTC by Maarten van Hulsentop
Modified: 2017-08-24 23:29 UTC (History)
0 users



Attachments
webdav webapps folder to ease reproduction (2.03 KB, application/x-zip-compressed)
2017-08-24 13:51 UTC, Maarten van Hulsentop
Details

Note You need to log in before you can comment on or make changes to this bug.
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.