New submission from Lorenzo M. Catucci <lore...@sancho.ccd.uniroma2.it>:

Please find enclosed a small patch that helps coping with xml submissions
with an explicit charset defined.

While at it, I corrected the handling of type and subtype, which, according to
RFC 2045, must be matched case-insensitively.

For better long-term documentation, I added two test-cases, instead of
shoe-horning  in test_classify_xmlpost the test for both fixes.

As usual... The fix is really small, but if needed, I waive any copyright etc.

----------
assignedto: chrism
files: content-type-parameters.diff
messages: 405
nosy: catucci, chrism
priority: bug
status: unread
title: repoze.who.classifiers - too strict content-type handling

__________________________________
Repoze Bugs <b...@bugs.repoze.org>
<http://bugs.repoze.org/issue145>
__________________________________
diff --git a/repoze/who/classifiers.py b/repoze/who/classifiers.py
--- a/repoze/who/classifiers.py
+++ b/repoze/who/classifiers.py
@@ -44,7 +44,7 @@
             if useragent.find(agent) != -1:
                 return 'dav'
     if request_method == 'POST':
-        if CONTENT_TYPE(environ) == 'text/xml':
+        if CONTENT_TYPE(environ).lower().startswith('text/xml'):
             return 'xmlpost'
     return 'browser'
 zope.interface.directlyProvides(default_request_classifier, IRequestClassifier)
diff --git a/repoze/who/tests/test_classifiers.py b/repoze/who/tests/test_classifiers.py
--- a/repoze/who/tests/test_classifiers.py
+++ b/repoze/who/tests/test_classifiers.py
@@ -32,6 +32,24 @@
         result = classifier(environ)
         self.assertEqual(result, 'xmlpost')
 
+    def test_classify_xmlpost_uppercase(self):
+        """RFC 2045, Sec. 5.1: The type, subtype, and parameter names
+           are not case sensitive"""
+        classifier = self._getFUT()
+        environ = self._makeEnviron({'CONTENT_TYPE':'TEXT/XML',
+                                     'REQUEST_METHOD':'POST'})
+        result = classifier(environ)
+        self.assertEqual(result, 'xmlpost')
+
+    def test_classify_rich_xmlpost(self):
+        """RFC 2046, sec. 4.1.2: A critical parameter that may be specified
+           in the Content-Type field for "text/plain" data is the character set.""" 
+        classifier = self._getFUT()
+        environ = self._makeEnviron({'CONTENT_TYPE':'text/xml; charset=UTF-8 (some comment)',
+                                     'REQUEST_METHOD':'POST'})
+        result = classifier(environ)
+        self.assertEqual(result, 'xmlpost')
+
     def test_classify_browser(self):
         classifier = self._getFUT()
         environ = self._makeEnviron({'CONTENT_TYPE':'text/xml',
_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to