summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Hellmann <doug.hellmann@gmail.com>2013-01-08 09:35:11 -0800
committerDoug Hellmann <doug.hellmann@gmail.com>2013-01-08 09:35:11 -0800
commitcbab3da568b67619abccf72626145c99cdf650c4 (patch)
treedf3f6c1b8dbc512b70053a98afd0e2f9866b2590
parent873f94d5a03dccd77d31680d1bf1f5eee917d9ff (diff)
parent1dd90ca0582757fc2090200800c8ffd92dd6fc2b (diff)
downloadpecan-cbab3da568b67619abccf72626145c99cdf650c4.tar.gz
Merge pull request #158 from ryanpetrello/next
Don't strip a dotted extension from the path unless it has a matching mimetype.
-rw-r--r--pecan/core.py12
-rw-r--r--pecan/tests/test_base.py22
2 files changed, 29 insertions, 5 deletions
diff --git a/pecan/core.py b/pecan/core.py
index 8155180..32185e5 100644
--- a/pecan/core.py
+++ b/pecan/core.py
@@ -368,13 +368,19 @@ class Pecan(object):
# lookup the controller, respecting content-type as requested
# by the file extension on the URI
path = request.pecan['routing_path']
+ request.pecan['extension'] = None
# attempt to guess the content type based on the file extension
if not request.pecan['content_type'] and '.' in path.split('/')[-1]:
- path, extension = splitext(path)
- request.pecan['extension'] = extension
+ new_path, extension = splitext(path)
+
# preface with a letter to ensure compat for 2.5
- request.pecan['content_type'] = guess_type('x' + extension)[0]
+ potential_type = guess_type('x' + extension)[0]
+
+ if potential_type is not None:
+ path = new_path
+ request.pecan['extension'] = extension
+ request.pecan['content_type'] = potential_type
controller, remainder = self.route(self.root, path)
cfg = _cfg(controller)
diff --git a/pecan/tests/test_base.py b/pecan/tests/test_base.py
index 13d1c94..043df38 100644
--- a/pecan/tests/test_base.py
+++ b/pecan/tests/test_base.py
@@ -863,7 +863,11 @@ class TestFileTypeExtensions(unittest.TestCase):
class RootController(object):
@expose(content_type=None)
def _default(self, *args):
- return request.pecan['extension']
+ ext = request.pecan['extension']
+ assert len(args) == 1
+ if ext:
+ assert ext not in args[0]
+ return ext or ''
return TestApp(Pecan(RootController()))
@@ -883,7 +887,7 @@ class TestFileTypeExtensions(unittest.TestCase):
assert r.body == ''
def test_multi_dot_extension(self):
- r = self.app_.get('/gradient.js.js')
+ r = self.app_.get('/gradient.min.js')
assert r.status_int == 200
assert r.body == '.js'
@@ -907,6 +911,20 @@ class TestFileTypeExtensions(unittest.TestCase):
r = app.get('/index.txt', expect_errors=True)
assert r.status_int == 404
+ def test_unknown_file_extension(self):
+ class RootController(object):
+ @expose(content_type=None)
+ def _default(self, *args):
+ assert 'example:x.tiny' in args
+ assert request.pecan['extension'] is None
+ return 'SOME VALUE'
+
+ app = TestApp(Pecan(RootController()))
+
+ r = app.get('/example:x.tiny')
+ assert r.status_int == 200
+ assert r.body == 'SOME VALUE'
+
class TestContentTypeByAcceptHeaders(unittest.TestCase):