Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,29 @@ def _output():
resp = app.get('/test', status=403)
assert 'ERROR!!!' in resp, resp

def test_custom_error_document_handles_malformed_query_string(self):
class ErrorController(TGController):
@expose()
def document(self, *args, **kw):
return 'ERROR!!!'

class RootController(TGController):
error = ErrorController()

@expose()
def test(self):
return 'OK'

conf = AppConfig(minimal=True, root_controller=RootController())
conf['errorpage.enabled'] = True
conf['errorpage.status_codes'] = [400]
conf['errorpage.handle_exceptions'] = False
app = conf.make_wsgi_app(full_stack=True)
app = TestApp(app)

resp = app.get('/test?x=%AD', status=400)
assert 'ERROR!!!' in resp, resp

def test_error_document_passthrough(self):
class ErrorController(TGController):
@expose()
Expand Down
6 changes: 6 additions & 0 deletions tests/test_tg_controller_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,12 @@ def test_named_arguments_override_positional(self):
r = self.app.get('/hello/YourName/silly?name=You&more=1')
assert 'Hello You' in r, r

def test_malformed_query_parameter_name_is_bad_request(self):
self.app.get('/?percent%ADd=1', status=400)

def test_malformed_query_parameter_value_is_bad_request(self):
self.app.get('/?x=%AD', status=400)

def test_response_without_charset(self):
r = self.app.get('/index_unicode')
assert 'Hello World' in r, r
Expand Down
6 changes: 5 additions & 1 deletion tg/request_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ def args_params(self):
# This was: dict(((str(n), v) for n,v in self.params.mixed().items()))
# so that keys were all strings making possible to use them as arguments.
# Now it seems that all keys are always strings, did WebOb change behavior?
params = self.params.mixed()
try:
params = self.params.mixed()
except UnicodeDecodeError:
self.__dict__["args_params"] = {}
raise HTTPBadRequest("Invalid request parameters")
if (
self.content_type
and self.content_type.lower() == "application/json"
Expand Down
Loading