summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/http/server.py6
-rw-r--r--Lib/test/test_httpservers.py19
2 files changed, 22 insertions, 3 deletions
diff --git a/Lib/http/server.py b/Lib/http/server.py
index c1607b3..1f6a62b 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -768,9 +768,9 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
words = filter(None, words)
path = os.getcwd()
for word in words:
- drive, word = os.path.splitdrive(word)
- head, word = os.path.split(word)
- if word in (os.curdir, os.pardir): continue
+ if os.path.dirname(word) or word in (os.curdir, os.pardir):
+ # Ignore components that are not a simple file/directory name
+ continue
path = os.path.join(path, word)
if trailing_slash:
path += '/'
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
index 3856d00..b313aee 100644
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -12,6 +12,7 @@ import os
import sys
import re
import base64
+import ntpath
import shutil
import urllib.parse
import html
@@ -960,6 +961,24 @@ class SimpleHTTPRequestHandlerTestCase(unittest.TestCase):
path = self.handler.translate_path('//filename?foo=bar')
self.assertEqual(path, self.translated)
+ def test_windows_colon(self):
+ with support.swap_attr(server.os, 'path', ntpath):
+ path = self.handler.translate_path('c:c:c:foo/filename')
+ path = path.replace(ntpath.sep, os.sep)
+ self.assertEqual(path, self.translated)
+
+ path = self.handler.translate_path('\\c:../filename')
+ path = path.replace(ntpath.sep, os.sep)
+ self.assertEqual(path, self.translated)
+
+ path = self.handler.translate_path('c:\\c:..\\foo/filename')
+ path = path.replace(ntpath.sep, os.sep)
+ self.assertEqual(path, self.translated)
+
+ path = self.handler.translate_path('c:c:foo\\c:c:bar/filename')
+ path = path.replace(ntpath.sep, os.sep)
+ self.assertEqual(path, self.translated)
+
class MiscTestCase(unittest.TestCase):
def test_all(self):