aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMaarten ter Huurne <maarten@boxingbeetle.com>2019-02-18 22:51:51 +0100
committerMaarten ter Huurne <maarten@boxingbeetle.com>2019-02-18 23:06:51 +0100
commit76da463522966aeb4bb0764788aa878bab422e42 (patch)
treeda1c497525f565f276f248fc388bd6106c051532 /tests
parent9963f3d5b77ec0bb2cc1a9c3a4679246f37833d4 (diff)
downloadmarkupsafe-76da463522966aeb4bb0764788aa878bab422e42.tar.gz
Add NULL check after native call to __html__ method
If the method raises an exception, PyObject_CallObject() returns NULL, but the code didn't check for that, which led to a segfault. Fixes #108
Diffstat (limited to 'tests')
-rw-r--r--tests/test_exception_custom_html.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/test_exception_custom_html.py b/tests/test_exception_custom_html.py
new file mode 100644
index 0000000..5f9ffde
--- /dev/null
+++ b/tests/test_exception_custom_html.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+import pytest
+
+from markupsafe import escape
+
+
+class CustomHtmlThatRaises(object):
+ def __html__(self):
+ raise ValueError(123)
+
+
+def test_exception_custom_html():
+ """Checks whether exceptions in custom __html__ implementations are
+ propagated correctly.
+
+ There was a bug in the native implementation at some point:
+ https://github.com/pallets/markupsafe/issues/108
+ """
+ obj = CustomHtmlThatRaises()
+ with pytest.raises(ValueError):
+ escape(obj)