diff --git a/pecan/core.py b/pecan/core.py index f023608..734b6e6 100644 --- a/pecan/core.py +++ b/pecan/core.py @@ -137,6 +137,8 @@ class Pecan(object): return node, remainder except NonCanonicalPath, e: if self.force_canonical and not _cfg(e.controller).get('accept_noncanonical', False): + if request.method == 'POST': + raise RuntimeError, "You have POSTed to a URL '%s' which requires a slash. Most browsers will not maintain POST data when redirected. Please update you code to POST to '%s/' or set force_canonical to False" % (request.routing_path, request.routing_path) raise exc.HTTPFound(add_slash=True) return e.controller, e.remainder diff --git a/tests/test_base.py b/tests/test_base.py index 4136314..6eb9f42 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -693,6 +693,13 @@ class TestEngines(object): r = app.get('/sub', status=302) assert r.status_int == 302 + try: + r = app.post('/sub', dict(foo=1)) + raise Exception, "Post should fail" + except Exception, e: + raise e + assert isinstance(e, RuntimeError) + r = app.get('/arg/index/foo') assert r.status_int == 200 assert r.body == 'foo' @@ -714,6 +721,10 @@ class TestEngines(object): assert r.status_int == 200 assert 'subindex' in r.body + r = app.post('/sub', dict(foo=1)) + assert r.status_int == 200 + assert 'subindex' in r.body + r = app.get('/sub/') assert r.status_int == 200 assert 'subindex' in r.body