Project

General

Profile

Error #913

Some strings serialized as binary instead of unicode cause errors

Added by Marcin Szewczyk almost 10 years ago.

Status:
New
Priority:
Normal
Category:
General
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Source:
Customer
Detected on version:
Redmine version:
Redmine 1.4.3
Milestones:

Description

Hi,

I have just plugged localizable 0.2.0 in my Redmine 1.4.4+dfsg1-2+deb7u1 (Debian Wheezy) with PostgreSQL as the backend. After adding translations some strings caused errors both on plugin's configuration page and on Redmine Issues page. I have used parts of localizable 0.3.0 to fix the configuration page:

diff -ur localizable.0.2.0/app/views/settings/_localizable.html.erb localizable.0.3.0/app/views/settings/_localizable.html.erb
--- localizable.0.2.0/app/views/settings/_localizable.html.erb    2012-06-12 01:06:01.000000000 +0200
+++ localizable.0.3.0/app/views/settings/_localizable.html.erb    2012-11-06 15:52:59.000000000 +0100
@@ -77,8 +77,8 @@
   <tbody>
   <%- @settings["locales"][element[:name]] = {} if @settings["locales"][element[:name]].nil? -%>
   <%- element[:objects].each do |object| -%>
-    <%- if type != object.type.to_s -%>
-    <%- type = object.type.to_s -%>
+    <%- if type != object.class.to_s -%>
+    <%- type = object.class.to_s -%>
     <tr>
       <td colspan="<%= @settings["locales_to_translate"].size + 1 %>">
         <b><em><%= l(type_labels[object.type.to_s.gsub(/CustomField/, "")]) %></em></b>
@@ -92,8 +92,8 @@
       </td>
       <%- @settings["locales_to_translate"].each do |locale| -%>
       <td align="left">
-        <input name="settings[locales][<%= element[:name] %>][<%= object.id %>][<%= locale %>]" 
-               value="<%= @settings["locales"][element[:name]][object.id.to_s][locale] %>" />
+        <input name="settings[locales][<%= element[:name] %>][<%= object.id %>][<%= locale.to_s.force_encoding("UTF-8") %>]" 
+               value="<%= @settings["locales"][element[:name]][object.id.to_s][locale].to_s.force_encoding("UTF-8") %>" />
       </td>
       <%- end -%>
     </tr>

But I was still getting errors (incompatible character encodings: ASCII-8BIT and UTF-8) on the Issues page. The patch attached fixes that problem as well.

The curious thing is that the mechanizm serializing my strings seems to be unstable. For example it would serialize 1-letter string "ą" (\xc4\x85) to a binary, but a string "Rozwiązanie" containing "ą" to a unicode string. One of strings causing problems because of being converted to binary (QsWCxIVk in base64) was "Błąd" (B\xc5\x82\xc4\x85d).

I do not know Ruby at all, so I am not sure if it was the correct way to fix that.


Files

0001-redmine-localizable-v0.2.1-to-fix-UTF-8-problems.patch (3.42 KB) 0001-redmine-localizable-v0.2.1-to-fix-UTF-8-problems.patch patch for version 0.2.0 (bumping to 0.2.1) Marcin Szewczyk, 2014-11-28 23:48

No data to display

Also available in: Atom PDF