You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2022/02/11 16:00:44 UTC
[tomcat] branch 9.0.x updated (d06a867 -> c2faa05)
This is an automated email from the ASF dual-hosted git repository.
markt pushed a change to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git.
from d06a867 Remove trailing space
new 16b3580 Fix a potential exception when generating a WebDAV multi-status response
new c2faa05 Improve human readability of WebDAV XML responses.
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../apache/catalina/servlets/WebdavServlet.java | 19 ++++---------
java/org/apache/catalina/util/XMLWriter.java | 32 ++++++++++++++++------
webapps/docs/changelog.xml | 11 ++++++++
3 files changed, 40 insertions(+), 22 deletions(-)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[tomcat] 01/02: Fix a potential exception when generating a WebDAV multi-status response
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 16b3580af462a7ee932835a527d961ee9b1be648
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Feb 11 15:33:44 2022 +0000
Fix a potential exception when generating a WebDAV multi-status response
Fix a potential StringIndexOutOfBoundsException exception when
generating a WebDAV multi-status response after an error during a copy
or delete.
Report the paths relative to the server root for any resources with an
error.
---
java/org/apache/catalina/servlets/WebdavServlet.java | 19 +++++--------------
webapps/docs/changelog.xml | 6 ++++++
2 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/java/org/apache/catalina/servlets/WebdavServlet.java b/java/org/apache/catalina/servlets/WebdavServlet.java
index 73c0c5f..b5b08f8 100644
--- a/java/org/apache/catalina/servlets/WebdavServlet.java
+++ b/java/org/apache/catalina/servlets/WebdavServlet.java
@@ -1921,22 +1921,18 @@ public class WebdavServlet extends DefaultServlet {
* @param req Servlet request
* @param resp Servlet response
* @param errorList List of error to be displayed
+ *
* @throws IOException If an IO error occurs
*/
private void sendReport(HttpServletRequest req, HttpServletResponse resp,
- Hashtable<String,Integer> errorList)
- throws IOException {
+ Hashtable<String,Integer> errorList) throws IOException {
resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
- String absoluteUri = req.getRequestURI();
- String relativePath = getRelativePath(req);
-
XMLWriter generatedXML = new XMLWriter();
generatedXML.writeXMLHeader();
- generatedXML.writeElement("D", DEFAULT_NAMESPACE, "multistatus",
- XMLWriter.OPENING);
+ generatedXML.writeElement("D", DEFAULT_NAMESPACE, "multistatus", XMLWriter.OPENING);
Enumeration<String> pathList = errorList.keys();
while (pathList.hasMoreElements()) {
@@ -1947,18 +1943,14 @@ public class WebdavServlet extends DefaultServlet {
generatedXML.writeElement("D", "response", XMLWriter.OPENING);
generatedXML.writeElement("D", "href", XMLWriter.OPENING);
- String toAppend = errorPath.substring(relativePath.length());
- if (!toAppend.startsWith("/")) {
- toAppend = "/" + toAppend;
- }
- generatedXML.writeText(absoluteUri + toAppend);
+ generatedXML.writeText(getServletContext().getContextPath() + errorPath);
generatedXML.writeElement("D", "href", XMLWriter.CLOSING);
+
generatedXML.writeElement("D", "status", XMLWriter.OPENING);
generatedXML.writeText("HTTP/1.1 " + errorCode + " ");
generatedXML.writeElement("D", "status", XMLWriter.CLOSING);
generatedXML.writeElement("D", "response", XMLWriter.CLOSING);
-
}
generatedXML.writeElement("D", "multistatus", XMLWriter.CLOSING);
@@ -1966,7 +1958,6 @@ public class WebdavServlet extends DefaultServlet {
Writer writer = resp.getWriter();
writer.write(generatedXML.toString());
writer.close();
-
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index c92ed56..1c80769 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -139,6 +139,12 @@
<code>TomcatPrincipal</code> and <code>GenericPrincipal</code>.
Patch provided by Carsten Klein. (michaelo)
</add>
+ <fix>
+ Fix a potential <code>StringIndexOutOfBoundsException</code> exception
+ when generating a WebDAV multi-status response after an error during a
+ copy or delete. Report the paths relative to the server root for any
+ resources with an error. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[tomcat] 02/02: Improve human readability of WebDAV XML responses.
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit c2faa058fcebefb4a61a5669b00018308f4aaa91
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Feb 11 15:35:59 2022 +0000
Improve human readability of WebDAV XML responses.
---
java/org/apache/catalina/util/XMLWriter.java | 32 +++++++++++++++++++++-------
webapps/docs/changelog.xml | 5 +++++
2 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/java/org/apache/catalina/util/XMLWriter.java b/java/org/apache/catalina/util/XMLWriter.java
index 937fd07..019c4b9 100644
--- a/java/org/apache/catalina/util/XMLWriter.java
+++ b/java/org/apache/catalina/util/XMLWriter.java
@@ -24,10 +24,8 @@ import java.io.Writer;
*/
public class XMLWriter {
-
// -------------------------------------------------------------- Constants
-
/**
* Opening tag.
*/
@@ -48,7 +46,6 @@ public class XMLWriter {
// ----------------------------------------------------- Instance Variables
-
/**
* Buffer.
*/
@@ -61,8 +58,10 @@ public class XMLWriter {
protected final Writer writer;
- // ----------------------------------------------------------- Constructors
+ protected boolean lastWriteWasOpen;
+
+ // ----------------------------------------------------------- Constructors
/**
* New XML writer utility that will store its data in an internal buffer.
@@ -87,7 +86,6 @@ public class XMLWriter {
// --------------------------------------------------------- Public Methods
-
/**
* Retrieve generated XML.
*
@@ -138,6 +136,9 @@ public class XMLWriter {
if ((namespace != null) && (namespace.length() > 0)) {
switch (type) {
case OPENING:
+ if (lastWriteWasOpen) {
+ buffer.append('\n');
+ }
if (namespaceInfo != null) {
buffer.append("<" + namespace + ":" + name + " xmlns:"
+ namespace + "=\""
@@ -145,32 +146,47 @@ public class XMLWriter {
} else {
buffer.append("<" + namespace + ":" + name + ">");
}
+ lastWriteWasOpen = true;
break;
case CLOSING:
buffer.append("</" + namespace + ":" + name + ">\n");
+ lastWriteWasOpen = false;
break;
case NO_CONTENT:
default:
+ if (lastWriteWasOpen) {
+ buffer.append('\n');
+ }
if (namespaceInfo != null) {
buffer.append("<" + namespace + ":" + name + " xmlns:"
+ namespace + "=\""
- + namespaceInfo + "\"/>");
+ + namespaceInfo + "\"/>\n");
} else {
- buffer.append("<" + namespace + ":" + name + "/>");
+ buffer.append("<" + namespace + ":" + name + "/>\n");
}
+ lastWriteWasOpen = false;
break;
}
} else {
switch (type) {
case OPENING:
+ if (lastWriteWasOpen) {
+ buffer.append('\n');
+ }
buffer.append("<" + name + ">");
+ lastWriteWasOpen = true;
break;
case CLOSING:
buffer.append("</" + name + ">\n");
+ lastWriteWasOpen = false;
break;
case NO_CONTENT:
default:
- buffer.append("<" + name + "/>");
+ if (lastWriteWasOpen) {
+ buffer.append('\n');
+ }
+ buffer.append("<" + name + "/>\n");
+ lastWriteWasOpen = false;
break;
}
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 1c80769..4a2a6c0 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -145,6 +145,11 @@
copy or delete. Report the paths relative to the server root for any
resources with an error. (markt)
</fix>
+ <fix>
+ Improve the format of WebDAV XML responses to make them easier for
+ humans to read. The change ensures that there is always a line break
+ before starting a new element. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org