[mod_python] mod_python.publisher buglet [ + patch ]

Jamie Guinan guinan at bluebutton.com
Mon Sep 17 01:34:12 EST 2001


Hi,

I am just starting to look at mod_python (2.7.6), and I tried
using mod_python.publisher.  Works nicely at first glance,
but I found a small bug.

httpd.conf:

<Directory /var/www/html/pytest>
  AddHandler python-program .py
  PythonHandler mod_python.publisher
</Directory>

Now load
  http://localhost:81/pytest/index.py/

Note the trailing "/", publisher.py does not check if PATH_INFO
is empty after the / and I see a Python error in my browser,

  Mod_python error: "PythonHandler mod_python.publisher"

  Traceback (innermost last):

  File "/usr/lib/python1.5/site-packages/mod_python/apache.py", line
  189, in Dispatch
  result = object(self.req)

  File "/usr/lib/python1.5/site-packages/mod_python/publisher.py", line
  93, in handler
  if func_path[-1] == ".":

  IndexError: string index out of range


Quickie patch (and bonus typo fix):

--cut below--
--- publisher.py.ori	Mon Sep 17 01:21:34 2001
+++ publisher.py	Mon Sep 17 01:33:03 2001
@@ -82,8 +82,13 @@
     # get the path PATH_INFO (everthing after script)
     if not _req.subprocess_env.has_key("PATH_INFO"):
         raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND
-
-    func_path = _req.subprocess_env["PATH_INFO"][1:] # skip fist /
+
+    func_path = _req.subprocess_env["PATH_INFO"][1:] # skip first /
+
+    # Check for empty func_path.
+    if not func_path:
+        raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND
+
     func_path = string.replace(func_path, "/", ".")
     if func_path[-1] == ".":
         func_path = func_path[:-1]
--cut above--

Cheers,
-Jamie




More information about the Mod_python mailing list