You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-commits@quetz.apache.org by gr...@apache.org on 2006/05/07 12:13:53 UTC

svn commit: r404748 - in /httpd/mod_python/trunk: Doc/appendixc.tex lib/python/mod_python/__init__.py src/include/mpversion.h src/requestobject.c test/htdocs/tests.py test/test.py

Author: grahamd
Date: Sun May  7 03:13:50 2006
New Revision: 404748

URL: http://svn.apache.org/viewcvs?rev=404748&view=rev
Log:
Directory argument supplied to req.add_handler() is canonicalized and a
trailing slash added automatically. This is needed to ensure that the
directory is always in POSIX path style as used by Apache and that
convention where directories associated with directives always have
trailing slash is adhered to. If this is not done, a different interpreter
can be chosen to that expected when the PythonInterpPerDirective is used.
The same sort of modification was also made for the directory argument
of the req.register_input_filter() and req.register_output_filter()
functions. (MODPYTHON-161) (MODPYTHON-103)


Modified:
    httpd/mod_python/trunk/Doc/appendixc.tex
    httpd/mod_python/trunk/lib/python/mod_python/__init__.py
    httpd/mod_python/trunk/src/include/mpversion.h
    httpd/mod_python/trunk/src/requestobject.c
    httpd/mod_python/trunk/test/htdocs/tests.py
    httpd/mod_python/trunk/test/test.py

Modified: httpd/mod_python/trunk/Doc/appendixc.tex
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/Doc/appendixc.tex?rev=404748&r1=404747&r2=404748&view=diff
==============================================================================
--- httpd/mod_python/trunk/Doc/appendixc.tex (original)
+++ httpd/mod_python/trunk/Doc/appendixc.tex Sun May  7 03:13:50 2006
@@ -313,6 +313,15 @@
       When using stacked handlers and a \code{SERVER_RETURN} exception was
       used to return an \code{OK} status for that handler, any following
       handlers weren't being run if appropriate for the phase.
+    \item
+      (\citetitle[http://issues.apache.org/jira/browse/MODPYTHON-161]{MODPYTHON-161})
+      Directory argument supplied to \code{req.add_handler()} is
+      canonicalized and a trailing slash added automatically. This is
+      needed to ensure that the directory is always in POSIX path style as
+      used by Apache and that convention where directories associated with
+      directives always have trailing slash is adhered to. If this is not
+      done, a different interpreter can be chosen to that expected when the
+      \code{PythonInterpPerDirective} is used.
   \end{itemize}
 
 \chapter{Changes from Version (3.2.7)\label{app-changes-from-3.2.7}}

Modified: httpd/mod_python/trunk/lib/python/mod_python/__init__.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/lib/python/mod_python/__init__.py?rev=404748&r1=404747&r2=404748&view=diff
==============================================================================
--- httpd/mod_python/trunk/lib/python/mod_python/__init__.py (original)
+++ httpd/mod_python/trunk/lib/python/mod_python/__init__.py Sun May  7 03:13:50 2006
@@ -20,5 +20,5 @@
 __all__ = ["apache", "cgihandler", "psp",
            "publisher", "util", "python22"]
 
-version = "3.3.0-dev-20060506"
+version = "3.3.0-dev-20060507"
 

Modified: httpd/mod_python/trunk/src/include/mpversion.h
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/include/mpversion.h?rev=404748&r1=404747&r2=404748&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/include/mpversion.h (original)
+++ httpd/mod_python/trunk/src/include/mpversion.h Sun May  7 03:13:50 2006
@@ -1,5 +1,5 @@
 #define MPV_MAJOR 3
 #define MPV_MINOR 3
 #define MPV_PATCH 0
-#define MPV_BUILD 20060506
-#define MPV_STRING "3.3.0-dev-20060506"
+#define MPV_BUILD 20060507
+#define MPV_STRING "3.3.0-dev-20060507"

Modified: httpd/mod_python/trunk/src/requestobject.c
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/requestobject.c?rev=404748&r1=404747&r2=404748&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/requestobject.c (original)
+++ httpd/mod_python/trunk/src/requestobject.c Sun May  7 03:13:50 2006
@@ -148,6 +148,29 @@
                                      "Invalid phase: %s", phase));
         return NULL;
     }
+
+    /* Canonicalize path and add trailing slash at
+     * this point if directory was provided. */
+
+    if (dir) {
+
+        char *newpath = 0;
+        apr_status_t rv;
+
+        rv = apr_filepath_merge(&newpath, NULL, dir,
+                                APR_FILEPATH_TRUENAME,
+                                self->request_rec->pool);
+
+        /* If there is a failure, use the original path
+         * which was supplied. */
+
+        if (rv == APR_SUCCESS || rv == APR_EPATHWILD) {
+            dir = newpath;
+            if (dir[strlen(dir) - 1] != '/') {
+                dir = apr_pstrcat(self->request_rec->pool, dir, "/", NULL);
+            }
+        }
+    }
     
     /* which phase are we processing? */
     currphase = PyString_AsString(self->phase);
@@ -263,7 +286,7 @@
 {
     char *name;
     char *handler;
-    const char *dir = NULL;
+    char *dir = NULL;
     py_req_config *req_config;
     py_handler *fh;
 
@@ -276,7 +299,32 @@
     fh = (py_handler *) apr_pcalloc(self->request_rec->pool,
                                     sizeof(py_handler));
     fh->handler = apr_pstrdup(self->request_rec->pool, handler);
-    if (dir) fh->directory = apr_pstrdup(self->request_rec->pool, dir);
+
+    /* Canonicalize path and add trailing slash at
+     * this point if directory was provided. */
+
+    if (dir) {
+
+        char *newpath = 0;
+        apr_status_t rv;
+
+        rv = apr_filepath_merge(&newpath, NULL, dir,
+                                APR_FILEPATH_TRUENAME,
+                                self->request_rec->pool);
+
+        /* If there is a failure, use the original path
+         * which was supplied. */
+
+        if (rv == APR_SUCCESS || rv == APR_EPATHWILD) {
+            dir = newpath;
+            if (dir[strlen(dir) - 1] != '/') {
+                dir = apr_pstrcat(self->request_rec->pool, dir, "/", NULL);
+            }
+            fh->directory = dir;
+        } else {
+            fh->directory = apr_pstrdup(self->request_rec->pool, dir);
+        }
+    }
 
     apr_hash_set(req_config->in_filters,
                  apr_pstrdup(self->request_rec->pool, name),
@@ -296,7 +344,7 @@
 {
     char *name;
     char *handler;
-    const char *dir = NULL;
+    char *dir = NULL;
     py_req_config *req_config;
     py_handler *fh;
 
@@ -309,7 +357,32 @@
     fh = (py_handler *) apr_pcalloc(self->request_rec->pool,
                                     sizeof(py_handler));
     fh->handler = apr_pstrdup(self->request_rec->pool, handler);
-    if (dir) fh->directory = apr_pstrdup(self->request_rec->pool, dir);
+
+    /* Canonicalize path and add trailing slash at
+     * this point if directory was provided. */
+
+    if (dir) {
+
+        char *newpath = 0;
+        apr_status_t rv;
+
+        rv = apr_filepath_merge(&newpath, NULL, dir,
+                                APR_FILEPATH_TRUENAME,
+                                self->request_rec->pool);
+
+        /* If there is a failure, use the original path
+         * which was supplied. */
+
+        if (rv == APR_SUCCESS || rv == APR_EPATHWILD) {
+            dir = newpath;
+            if (dir[strlen(dir) - 1] != '/') {
+                dir = apr_pstrcat(self->request_rec->pool, dir, "/", NULL);
+            }
+            fh->directory = dir;
+        } else {
+            fh->directory = apr_pstrdup(self->request_rec->pool, dir);
+        }
+    }
 
     apr_hash_set(req_config->out_filters,
                  apr_pstrdup(self->request_rec->pool, name),

Modified: httpd/mod_python/trunk/test/htdocs/tests.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/test/htdocs/tests.py?rev=404748&r1=404747&r2=404748&view=diff
==============================================================================
--- httpd/mod_python/trunk/test/htdocs/tests.py (original)
+++ httpd/mod_python/trunk/test/htdocs/tests.py Sun May  7 03:13:50 2006
@@ -611,6 +611,32 @@
 
     return apache.OK
 
+def test_req_add_handler_directory(req):
+    # dir1 will not have a trailing slash and on Win32
+    # will use back slashes and not forward slashes.
+    dir1 = os.path.dirname(__file__)
+    if req.phase == "PythonFixupHandler":
+        req.add_handler("PythonHandler", "tests::test_req_add_handler_directory", dir1)
+    else:
+	# dir2 should only use forward slashes and
+	# should have a trailing forward slash added by
+	# call to req.add_handler(). When dir1 and dir2
+	# are normalised for current operating system,
+        # they should be equivalent.
+        dir2 = req.hlist.directory
+        if dir2[-1] != '/' or dir2.count('\\') != 0:
+            req.write('test failed')
+        else:
+            dir1 = os.path.normpath(dir1)
+            dir2 = os.path.normpath(dir2)
+            if dir2 != dir1:
+                req.write('test failed')
+            else:
+                req.write('test ok')
+        
+    return apache.OK
+
+
 def req_allow_methods(req):
 
     req.allow_methods(["PYTHONIZE"])

Modified: httpd/mod_python/trunk/test/test.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/test/test.py?rev=404748&r1=404747&r2=404748&view=diff
==============================================================================
--- httpd/mod_python/trunk/test/test.py (original)
+++ httpd/mod_python/trunk/test/test.py Sun May  7 03:13:50 2006
@@ -586,6 +586,28 @@
         if (rsp != "test ok"):
             self.fail(`rsp`)
 
+    def test_req_add_handler_directory_conf(self):
+
+        c = VirtualHost("*",
+                        ServerName("test_req_add_handler_directory"),
+                        DocumentRoot(DOCUMENT_ROOT),
+                        Directory(DOCUMENT_ROOT,
+                                  SetHandler("mod_python"),
+                                  PythonInterpPerDirective("On"),
+                                  PythonFixupHandler("tests::test_req_add_handler_directory"),
+                                  PythonDebug("On")))
+        return str(c)
+
+    def test_req_add_handler_directory(self):
+        # Checking that directory is canonicalized and trailing
+        # slash is added.
+
+        print """\n  * Testing req.add_handler() directory"""
+        rsp = self.vhost_get("test_req_add_handler_directory")
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
     def test_accesshandler_add_handler_to_empty_hl_conf(self):
         # Note that there is no PythonHandler specified in the the VirtualHost
         # config. We want to see if req.add_handler will work when the 
@@ -2545,6 +2567,7 @@
         perRequestSuite.addTest(PerRequestTestCase("test_req_add_bad_handler"))
         perRequestSuite.addTest(PerRequestTestCase("test_req_add_empty_handler_string"))
         perRequestSuite.addTest(PerRequestTestCase("test_req_add_handler_empty_phase"))
+        perRequestSuite.addTest(PerRequestTestCase("test_req_add_handler_directory"))
         perRequestSuite.addTest(PerRequestTestCase("test_accesshandler_add_handler_to_empty_hl"))
         perRequestSuite.addTest(PerRequestTestCase("test_req_allow_methods"))
         perRequestSuite.addTest(PerRequestTestCase("test_req_get_basic_auth_pw"))