Test URL escaping in directory listing.
authorEmil Mikulic <emikulic@gmail.com>
Sat, 16 Apr 2011 09:27:06 +0000 (19:27 +1000)
committerEmil Mikulic <emikulic@gmail.com>
Sun, 28 Apr 2013 10:56:04 +0000 (20:56 +1000)
devel/test.py

index 19a5183..a368755 100755 (executable)
@@ -3,6 +3,9 @@ import unittest
 import socket
 import signal
 import re
+import os
+
+WWWROOT = "tmp.httpd.tests"
 
 class Conn:
     def __init__(self):
@@ -11,7 +14,7 @@ class Conn:
         self.s.connect(("0.0.0.0", self.port))
         # connect throws socket.error on connection refused
 
-    def get(self, url, http_ver=None, endl="\n",
+    def get(self, url, http_ver="1.0", endl="\n",
             req_hdrs={"User-Agent": "test.py"}):
         req = "GET "+url
         if http_ver is not None:
@@ -66,6 +69,17 @@ class TestCases(unittest.TestCase):
             "You requested an invalid URL: %s\n"%path,
             'Generated by darkhttpd')
 
+    def test_dirlist_escape(self):
+        fn = WWWROOT+"/escape#this"
+        open(fn, "w").write("x"*12345)
+        try:
+            resp = Conn().get("/")
+        finally:
+            os.unlink(fn)
+        status, hdrs, body = parse(resp)
+        self.assertEquals(ord("#"), 0x23)
+        self.assertContains(body, "escape%23this", "12345")
+
 def nerf(s):
     return re.sub("[^a-zA-Z0-9]", "_", s)