Module: check_mk
Branch: master
Commit: 5e2e93bbc17f73a802291d0ef1ff7214df168e69
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5e2e93bbc17f73…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Dec 19 12:11:09 2014 +0100
Fix internal UTF-8 problem in html.attrencode
---
web/htdocs/html_mod_python.py | 2 +-
web/htdocs/htmllib.py | 9 +++++----
web/htdocs/index.py | 4 ++--
3 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/web/htdocs/html_mod_python.py b/web/htdocs/html_mod_python.py
index 1d9dc24..99bc8bd 100644
--- a/web/htdocs/html_mod_python.py
+++ b/web/htdocs/html_mod_python.py
@@ -145,7 +145,7 @@ class html_mod_python(htmllib.html):
def log(self, msg):
if type(msg) != str:
msg = repr(msg)
- self.req.log_error(msg, apache.APLOG_WARNING)
+ self.req.log_error(msg, apache.APLOG_ERR)
def http_redirect(self, url):
self.set_http_header('Location', url)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 61bb742..36e6cec 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -1275,15 +1275,16 @@ class html:
# From here: Former not class functions
- # This function returns a str object, never unicode!
# Encode HTML attributes: replace " with ", also replace
- # < and >. This code is slow.
+ # < and >. This code is slow. Works on str and unicode without
+ # changing the type. Also works on things that can be converted
+ # with %s.
def attrencode(self, value):
ty = type(value)
if ty == int:
return str(value)
- elif ty not in [str, unicode]:
- value = str(value)
+ elif ty not in [str, unicode]: # also possible: type Exception!
+ value = "%s" % value # Note: this allows Unicode. value might not
have type str now
return value.replace('"',
""").replace("<",
"<").replace(">", ">")
diff --git a/web/htdocs/index.py b/web/htdocs/index.py
index 3dd259a..8150be5 100644
--- a/web/htdocs/index.py
+++ b/web/htdocs/index.py
@@ -272,7 +272,7 @@ def handler(req, fields = None, profiling = True):
html.header(_("Configuration Error"))
html.show_error(unicode(html.attrencode(e)))
html.footer()
- apache.log_error(_("Configuration error: %s") % (e,),
apache.APLOG_ERR)
+ html.log(_("Configuration error: %s") % (e,))
except MKGeneralException, e:
if plain_error:
@@ -281,7 +281,7 @@ def handler(req, fields = None, profiling = True):
html.header(_("Error"))
html.show_error(unicode(html.attrencode(e)))
html.footer()
- apache.log_error(_("Error: %s") % (e,), apache.APLOG_ERR)
+ html.log(_("Error: %s") % (e,))
except livestatus.MKLivestatusNotFoundError, e:
if plain_error: