saily / redmine_stats

Redmine/Chiliproject ticket statistics
3 stars 2 forks source link

International characters in usernames are not shown correctly #2

Open mikini opened 6 years ago

mikini commented 6 years ago

I have usernames in Redmine containing Danish ø (HTML ) and å (HTML ) which ends up being wrongly formatted on the Munin graphs.

Output from MySQL and hence the plugin seems to be correct utf-8, they are interpreted fine by my shell but munin-graph doesn't render them correctly.

utf-8 char html entity hex Munin png representation
ø ø (ø) c3 b8 screenshot from 2017-10-26 16-47-29
å å (å) c3 a5 screenshot from 2017-10-26 16-47-39

According to the Munin docs (wiki) any chars except # and \ should be valid but no expected charset is specified. I have tried to dig into the perl code to see where and how the png are generated but haven't got to the bottom of it.

The rendered chars seems to be consistent with the 8859-1 codepage/charset. However, I do not get the expected result when changing the encoding from the current utf-8 to iso-8859-1 in line 108-109 as below. Now instead of the expected 0xf8 for ø in 8859-1 a value of 0x72 is output, for å (0xe5 in 8859-1) a value of 0x73.

diff --git a/redmine_stat.py b/redmine_stat.py
old mode 100644
new mode 100755
index 731f442..7ff8acd
--- a/redmine_stat.py
+++ b/redmine_stat.py
@@ -105,8 +105,8 @@ class TicketsByOwner(RedmineBase):

         def row(item):
             print "_v%s.label %s %s" % (item[3],
-                                        unicode(item[1]).encode("utf-8"),
-                                        unicode(item[2]).encode("utf-8"))
+                                        unicode(item[1]).encode("iso-8859-1"),
+                                        unicode(item[2]).encode("iso-8859-1"))
             print "_v%s.draw AREASTACK" % (item[3])

         self._result(row)
mikini commented 6 years ago

Sorry, I misread the raw output from the plugin and label updating on the website graphs seems to be delayed some cycles.

The above patch correctly encodes the usernames. Tested using Munin 2.0.25 from Ubuntu 16.04 LTS. I have committed the change to a fork at https://github.com/VestergaardCompany/redmine_stats and requested a pull in #3.