Module: check_mk
Branch: master
Commit: 2368f3360932477a815084bda081f556efe60f0f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2368f336093247…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jul 5 16:24:17 2018 +0200
Fixed unintended change in Encoder.urlencode_vars()
* GUI craw found this. Thanks!
* Extended the unit tests to find this earlier in the future
Change-Id: I0335bd628c4d0a05c5e264fad790cbe7ab407ba1
---
tests/unit/web/test_htmllib_Encoder.py | 1 +
web/htdocs/htmllib.py | 6 ++++++
2 files changed, 7 insertions(+)
diff --git a/tests/unit/web/test_htmllib_Encoder.py
b/tests/unit/web/test_htmllib_Encoder.py
index 74dfa83..4f51047 100644
--- a/tests/unit/web/test_htmllib_Encoder.py
+++ b/tests/unit/web/test_htmllib_Encoder.py
@@ -22,6 +22,7 @@ def test_htmllib_integration(register_builtin_html):
([("a", "+")], "a=%2B"),
([("a", " ")], "a=+"),
([("a", "/")], "a=%2F"),
+ ([("a", None)], "a="),
])
def test_urlencode_vars(inp, out):
result = htmllib.Encoder().urlencode_vars(inp)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 3e516db..1512f15 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -183,6 +183,12 @@ class Encoder(object):
value = str(value)
elif type(value) == unicode:
value = value.encode("utf-8")
+ elif value is None:
+ # TODO: This is not ideal and should better be cleaned up somehow.
Shouldn't
+ # variables with None values simply be skipped? We currently can not find
the
+ # call sites easily. This may be cleaned up once we establish typing.
Until then
+ # we need to be compatible with the previous behavior.
+ value = ""
#assert type(value) == str, "%s: %s" % (varname, value)