[Checkins] SVN: z3c.dav/trunk/src/z3c/dav/ When processing the input data for xml, try and parse the data that as no

Michael Kerrin michael.kerrin at openapp.ie
Wed May 9 14:35:36 EDT 2007


Log message for revision 75655:
  When processing the input data for xml, try and parse the data that as no
  content-type set and only raise a BadRequest when the data as being declared
  as xml.
  

Changed:
  U   z3c.dav/trunk/src/z3c/dav/publisher.py
  U   z3c.dav/trunk/src/z3c/dav/tests/test_publisher.py

-=-
Modified: z3c.dav/trunk/src/z3c/dav/publisher.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/publisher.py	2007-05-09 13:52:34 UTC (rev 75654)
+++ z3c.dav/trunk/src/z3c/dav/publisher.py	2007-05-09 18:35:35 UTC (rev 75655)
@@ -47,25 +47,28 @@
 
     def processInputs(self):
         """See IPublisherRequest."""
-        content_type = self.getHeader('content-type', '')
+        content_type = self.getHeader("content-type", None)
         content_type_params = None
-        if ';' in content_type:
-            parts = content_type.split(';', 1)
+        if content_type and ";" in content_type:
+            parts = content_type.split(";", 1)
             content_type = parts[0].strip().lower()
             content_type_params = parts[1].strip()
 
-        self.content_type = content_type
-
-        if content_type in ("text/xml", "application/xml") and \
+        if content_type in ("text/xml", "application/xml", None) and \
                self.getHeader("content-length", 0) > 0:
             etree = z3c.etree.getEngine()
             try:
                 self.xmlDataSource = etree.parse(self.bodyStream).getroot()
             except:
                 # There was an error parsing the body stream so this is a
-                # bad request.
-                raise interfaces.BadRequest(
-                    self, u"Invalid xml data passed")
+                # bad request if the content was declared as xml
+                if content_type is not None:
+                    raise interfaces.BadRequest(
+                        self, u"Invalid xml data passed")
+            else:
+                self.content_type = content_type or "application/xml"
+        else:
+            self.content_type = content_type
 
     def _createResponse(self):
         """Create a specific WebDAV response object."""

Modified: z3c.dav/trunk/src/z3c/dav/tests/test_publisher.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/tests/test_publisher.py	2007-05-09 13:52:34 UTC (rev 75654)
+++ z3c.dav/trunk/src/z3c/dav/tests/test_publisher.py	2007-05-09 18:35:35 UTC (rev 75655)
@@ -98,6 +98,17 @@
         request = create_request()
         self.assert_(verifyObject(IWebDAVResponse, request.response))
 
+    def test_nonxmlbody_type(self):
+        body = """<?xml version="1.0" encoding="utf-8" ?>
+        <somedoc>Bad End Tag</anotherdoc>
+        """
+        request = create_request(body, {"CONTENT_TYPE": "application/badxml",
+                                        "CONTENT_LENGTH": len(body)})
+        request.processInputs()
+
+        self.assertEqual(request.content_type, "application/badxml")
+        self.assertEqual(request.xmlDataSource, None)
+
     def test_invalidxml(self):
         body = """<?xml version="1.0" encoding="utf-8" ?>
         <somedoc>Bad End Tag</anotherdoc>
@@ -105,6 +116,7 @@
         request = create_request(body, {"CONTENT_TYPE": "application/xml",
                                         "CONTENT_LENGTH": len(body)})
         self.assertRaises(BadRequest, request.processInputs)
+        self.assertEqual(request.content_type, None)
 
 
 def test_suite():



More information about the Checkins mailing list