[Pkg-owncloud-commits] [php-sabredav] 10/19: Returning 418 I'm a Teapot in multistatus with no properties.

David Prévot taffit at moszumanska.debian.org
Tue Jan 5 03:12:56 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to tag 3.0.6
in repository php-sabredav.

commit ca732fa28197ba6ae9430635dcd9a73e18b3c453
Author: Evert Pot <me at evertpot.com>
Date:   Tue Nov 24 17:56:33 2015 -0500

    Returning 418 I'm a Teapot in multistatus with no properties.
---
 lib/DAV/Xml/Element/Response.php             | 21 +++++++++++++++++-
 tests/Sabre/DAV/Xml/Element/ResponseTest.php | 32 ++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/lib/DAV/Xml/Element/Response.php b/lib/DAV/Xml/Element/Response.php
index e1f1e51..15296f8 100644
--- a/lib/DAV/Xml/Element/Response.php
+++ b/lib/DAV/Xml/Element/Response.php
@@ -123,18 +123,37 @@ class Response implements Element {
             $writer->writeElement('{DAV:}status', 'HTTP/1.1 ' . $status . ' ' . \Sabre\HTTP\Response::$statusCodes[$status]);
         }
         $writer->writeElement('{DAV:}href', $writer->contextUri . \Sabre\HTTP\encodePath($this->getHref()));
+
+        $empty = true;
+
         foreach ($this->getResponseProperties() as $status => $properties) {
 
             // Skipping empty lists
             if (!$properties || (!ctype_digit($status) && !is_int($status))) {
                 continue;
             }
+            $empty = false;
             $writer->startElement('{DAV:}propstat');
             $writer->writeElement('{DAV:}prop', $properties);
             $writer->writeElement('{DAV:}status', 'HTTP/1.1 ' . $status . ' ' . \Sabre\HTTP\Response::$statusCodes[$status]);
             $writer->endElement(); // {DAV:}propstat
 
         }
+        if ($empty) {
+            /*
+             * The WebDAV spec _requires_ at least one DAV:propstat to appear for
+             * every DAV:response. In are circumstances however, there are no
+             * properties to encode.
+             *
+             * In those cases we MUST specify at least one DAV:propstat anyway, with
+             * no properties.
+             */
+            $writer->writeElement('{DAV:}propstat', [
+                '{DAV:}prop' => [],
+                '{DAV:}status' => 'HTTP/1.1 418 ' . \Sabre\HTTP\Response::$statusCodes[418]
+            ]);
+
+        }
 
     }
 
@@ -217,7 +236,7 @@ class Response implements Element {
                     $status = $elem['value']['{DAV:}status'];
                     list(, $status, ) = explode(' ', $status, 3);
                     $properties = isset($elem['value']['{DAV:}prop']) ? $elem['value']['{DAV:}prop'] : [];
-                    $propertyLists[$status] = $properties;
+                    if ($properties) $propertyLists[$status] = $properties;
                     break;
                 case '{DAV:}status' :
                     list(, $statusCode, ) = explode(' ', $elem['value'], 3);
diff --git a/tests/Sabre/DAV/Xml/Element/ResponseTest.php b/tests/Sabre/DAV/Xml/Element/ResponseTest.php
index 3ae2c63..5b44b05 100644
--- a/tests/Sabre/DAV/Xml/Element/ResponseTest.php
+++ b/tests/Sabre/DAV/Xml/Element/ResponseTest.php
@@ -245,6 +245,38 @@ class ResponseTest extends DAV\Xml\XmlTest {
     }
 
     /**
+     * @depends testSerialize
+     *
+     * The WebDAV spec _requires_ at least one DAV:propstat to appear for
+     * every DAV:response. In are circumstances however, there are no
+     * properties to encode.
+     *
+     * In those cases we MUST specify at least one DAV:propstat anyway, with
+     * no properties.
+     */
+    function testSerializeNoProperties() {
+
+        $innerProps = [];
+
+        $property = new Response('uri', $innerProps);
+        $xml = $this->write(['{DAV:}root' => ['{DAV:}response' => $property]]);
+
+        $this->assertXmlStringEqualsXmlString(
+'<?xml version="1.0"?>
+<d:root xmlns:d="DAV:">
+  <d:response>
+      <d:href>/uri</d:href>
+      <d:propstat>
+        <d:prop />
+        <d:status>HTTP/1.1 418 I\'m a teapot</d:status>
+      </d:propstat>
+  </d:response>
+</d:root>
+', $xml);
+
+    }
+
+    /**
      * In the case of {DAV:}prop, a deserializer should never get called, if
      * the property element is empty.
      */

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list