Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert HTTPException.description to string #2133

Merged
merged 1 commit into from May 17, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -16,6 +16,8 @@ Unreleased
characters. :issue:`2125`
- Type checking understands that calling ``headers.get`` with a string
default will always return a string. :issue:`2128`
- If ``HTTPException.description`` is not a string,
``get_description`` will convert it to a string. :issue:`2115`


Version 2.0.0
Expand Down
9 changes: 8 additions & 1 deletion src/werkzeug/exceptions.py
Expand Up @@ -156,7 +156,14 @@ def get_description(
scope: t.Optional[dict] = None,
) -> str:
"""Get the description."""
description = escape(self.description).replace("\n", "<br>") # type: ignore
if self.description is None:
description = ""
elif not isinstance(self.description, str):
description = str(self.description)
else:
description = self.description

description = escape(description).replace("\n", "<br>")
return f"<p>{description}</p>"

def get_body(
Expand Down
4 changes: 4 additions & 0 deletions tests/test_exceptions.py
Expand Up @@ -142,3 +142,7 @@ class TestResponse(Response):
exc = cls(response=TestResponse())
rp = exc.get_response({})
assert isinstance(rp, TestResponse)


def test_description_none():
HTTPException().get_response()