Module: check_mk
Branch: master
Commit: 8163fa22792ba43299a59fe11dd87e0491fe6d0f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8163fa22792ba4…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Aug 28 11:36:07 2017 +0200
5052 FIX Views: Fixed possible encoding exception when cells contain special chars
When doing a CSV export of a view that contains special characters it could happen
that the CSV export is incomplete and the last cell contained HTML code reporting
an exception (UnicodeEncodeError...).
Change-Id: Ie9221fea978059315d33e7ef183570ef91a83fce
---
.werks/5052 | 12 ++++++++++++
web/plugins/views/webservice.py | 14 ++++++++------
2 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/.werks/5052 b/.werks/5052
new file mode 100644
index 0000000..1474029
--- /dev/null
+++ b/.werks/5052
@@ -0,0 +1,12 @@
+Title: Views: Fixed possible encoding exception when cells contain special chars
+Level: 1
+Component: multisite
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1503912139
+Class: fix
+
+When doing a CSV export of a view that contains special characters it could happen
+that the CSV export is incomplete and the last cell contained HTML code reporting
+an exception (UnicodeEncodeError...).
diff --git a/web/plugins/views/webservice.py b/web/plugins/views/webservice.py
index 6160eed..cfb35f5 100644
--- a/web/plugins/views/webservice.py
+++ b/web/plugins/views/webservice.py
@@ -128,6 +128,12 @@ def render_csv(rows, view, group_cells, cells, num_columns,
show_checkboxes, exp
if export:
output_csv_headers(view)
+ def format_for_csv(raw_data):
+ # raw_data can also be int, float
+ content = "%s" % raw_data
+ stripped = html.strip_tags(content).replace('\n',
'').replace('"', '""')
+ return stripped.encode("utf-8")
+
csv_separator = html.var("csv_separator", ";")
first = True
for cell in group_cells + cells:
@@ -136,9 +142,7 @@ def render_csv(rows, view, group_cells, cells, num_columns,
show_checkboxes, exp
else:
html.write(csv_separator)
content = cell.export_title()
- # content can be int, float
- stripped = html.strip_tags(str(content)).replace('\n',
'').replace('"', '""')
- html.write('"%s"' % stripped.encode("utf-8"))
+ html.write('"%s"' % format_for_csv(content))
for row in rows:
html.write_text("\n")
@@ -150,9 +154,7 @@ def render_csv(rows, view, group_cells, cells, num_columns,
show_checkboxes, exp
html.write(csv_separator)
joined_row = join_row(row, cell)
tdclass, content = cell.render_content(joined_row)
- # content can be int, float
- stripped = html.strip_tags(str(content)).replace('\n',
'').replace('"', '""')
- html.write('"%s"' % stripped.encode("utf-8"))
+ html.write('"%s"' % format_for_csv(content))
multisite_layouts["csv_export"] = {
"title" : _("CSV data export"),