diff options
| author | pjenvey <devnull@localhost> | 2006-06-18 20:07:01 +0000 |
|---|---|---|
| committer | pjenvey <devnull@localhost> | 2006-06-18 20:07:01 +0000 |
| commit | 899bc9ef55578437f29a2c178f2d05fe2ebb372e (patch) | |
| tree | 92656e445634bbb7c696fefef98a089564b4b82c | |
| parent | 27c03f6b97bc1c49f5739c8e9f9bb5eb9d9c415e (diff) | |
| download | paste-899bc9ef55578437f29a2c178f2d05fe2ebb372e.tar.gz | |
Fixed urlparser classes to handle quoted (e.g. %20) URL paths.
Added tests for this
(Thanks Jose Galvez)
| -rw-r--r-- | docs/news.txt | 3 | ||||
| -rw-r--r-- | paste/urlparser.py | 10 | ||||
| -rw-r--r-- | tests/test_urlparser.py | 20 | ||||
| -rw-r--r-- | tests/urlparser_data/find_file/dir with spaces/test 4.html | 1 | ||||
| -rw-r--r-- | tests/urlparser_data/find_file/test 3.html | 1 |
5 files changed, 32 insertions, 3 deletions
diff --git a/docs/news.txt b/docs/news.txt index d5081a3..2944d36 100644 --- a/docs/news.txt +++ b/docs/news.txt @@ -16,6 +16,9 @@ NEWS * Fixed ``paste.translogger.TransLogger`` to log to the Apache combined log format as advertised. +* Fixed ``paste.urlparser`` classes to handle quoted characters (e.g. + %20) in URL paths. + 0.9.3 ----- diff --git a/paste/urlparser.py b/paste/urlparser.py index 829ec78..8ba52a8 100644 --- a/paste/urlparser.py +++ b/paste/urlparser.py @@ -7,6 +7,7 @@ WSGI applications that parse the URL and dispatch to on-disk resources import os import sys import imp +import urllib import pkg_resources import mimetypes import request @@ -192,7 +193,8 @@ class URLParser(object): # None of the index files found filename = None else: - filename = self.find_file(environ, name) + # Handle quoted chars (e.g. %20) + filename = self.find_file(environ, urllib.unquote(name)) if filename is None: return None, filename else: @@ -425,7 +427,8 @@ class StaticURLParser(object): # @@: This should obviously be configurable filename = 'index.html' else: - filename = request.path_info_pop(environ) + # Handle quoted chars (e.g. %20) + filename = urllib.unquote(request.path_info_pop(environ)) full = os.path.join(self.directory, filename) if not os.path.exists(full): return self.not_found(environ, start_response) @@ -510,7 +513,8 @@ class PkgResourcesParser(StaticURLParser): # @@: This should obviously be configurable filename = 'index.html' else: - filename = request.path_info_pop(environ) + # Handle quoted chars (e.g. %20) + filename = urllib.unquote(request.path_info_pop(environ)) resource = self.resource_name + '/' + filename if not self.egg.has_resource(resource): return self.not_found(environ, start_response) diff --git a/tests/test_urlparser.py b/tests/test_urlparser.py index ab6b2aa..cfad691 100644 --- a/tests/test_urlparser.py +++ b/tests/test_urlparser.py @@ -25,6 +25,18 @@ def test_find_file(): res = app.get('/test2.html') assert 'test2' in res assert res.header('content-type') == 'text/html' + res = app.get('/test 3.html') + assert 'test 3' in res + assert res.header('content-type') == 'text/html' + res = app.get('/test%203.html') + assert 'test 3' in res + assert res.header('content-type') == 'text/html' + res = app.get('/dir with spaces/test 4.html') + assert 'test 4' in res + assert res.header('content-type') == 'text/html' + res = app.get('/dir%20with%20spaces/test%204.html') + assert 'test 4' in res + assert res.header('content-type') == 'text/html' def test_deep(): app = make_app('deep') @@ -83,6 +95,14 @@ def test_static_parser(): res = testapp.get('/index.txt') assert res.body.strip() == 'index1' res = testapp.get('/index.txt/foo', status=400) + res = testapp.get('/test 3.html') + assert res.body.strip() == 'test 3' + res = testapp.get('/test%203.html') + assert res.body.strip() == 'test 3' + res = testapp.get('/dir with spaces/test 4.html') + assert res.body.strip() == 'test 4' + res = testapp.get('/dir%20with%20spaces/test%204.html') + assert res.body.strip() == 'test 4' def test_egg_parser(): app = PkgResourcesParser('Paste', 'paste') diff --git a/tests/urlparser_data/find_file/dir with spaces/test 4.html b/tests/urlparser_data/find_file/dir with spaces/test 4.html new file mode 100644 index 0000000..1121e31 --- /dev/null +++ b/tests/urlparser_data/find_file/dir with spaces/test 4.html @@ -0,0 +1 @@ +test 4 diff --git a/tests/urlparser_data/find_file/test 3.html b/tests/urlparser_data/find_file/test 3.html new file mode 100644 index 0000000..954a536 --- /dev/null +++ b/tests/urlparser_data/find_file/test 3.html @@ -0,0 +1 @@ +test 3 |
