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:16 UTC

[tomcat] branch 10.0.x updated (9c7bfb0 -> 63dc7fb)

This is an automated email from the ASF dual-hosted git repository.

markt pushed a change to branch 10.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git.


    from 9c7bfb0  Remove trailing space
     new 43e9c8c  Fix a potential exception when generating a WebDAV multi-status response
     new 63dc7fb  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 10.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 43e9c8c1195b33e52b06af9c348d21f51d643355
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 a9701b0..c6a0963 100644
--- a/java/org/apache/catalina/servlets/WebdavServlet.java
+++ b/java/org/apache/catalina/servlets/WebdavServlet.java
@@ -1922,22 +1922,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()) {
@@ -1948,18 +1944,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);
@@ -1967,7 +1959,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 e870286..8920403 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 10.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 63dc7fb7e94cbc0b44d0c5edb0648141b3dd51d3
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 8920403..7aa98fc 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