From 077d0548765e0fb264b7df2db665a05423b4f5d5 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Fri, 11 Nov 2016 14:52:11 -0500 Subject: [PATCH] LP#1641208: util.file no longer mangles UTF8 when writing JSON MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch ensures that JSON strings are converted to UTF8 before they are writing to XUL profile files by util.file. Doing this fixes a bug where by OU names like "ბიზნესისა" can get mangled in certain XUL client interfaces. To test ------- [1] Set an OU name to ბიზნესისა [2] In the transit list, note that the OU selector displays the name as ÑØÖÜÔáØáÐ. [3] Apply the patch (note that it's not necessary to rebuild the staff client to test this). [4] Restart the staff client, clearing cache beforehand. [5] Note that the OU name is now displayed correctly in the transit list. Signed-off-by: Galen Charlton Signed-off-by: Jason Etheridge --- Open-ILS/xul/staff_client/chrome/content/util/file.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Open-ILS/xul/staff_client/chrome/content/util/file.js b/Open-ILS/xul/staff_client/chrome/content/util/file.js index bc696dd6be..857f32ff5b 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/file.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/file.js @@ -103,7 +103,12 @@ util.file.prototype = { var obj_json; try { obj_json = js2JSON( obj ) + '\n'; } catch(E) { throw('Could not JSONify the object: ' + E); } - this.write_content(write_type,obj_json); + var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"] + .createInstance(Components.interfaces.nsIScriptableUnicodeConverter); + converter.charset = "UTF-8"; + var converted = converter.ConvertFromUnicode(obj_json); + + this.write_content(write_type,converted); } catch(E) { this.error.sdump('D_ERROR',this._file.path + '\nutil.file.write_object(): ' + E); @@ -126,7 +131,11 @@ util.file.prototype = { 'get_object' : function() { try { var data = this.get_content(); - var obj; try { obj = JSON2js( data ); } catch(E) { throw('Could not js-ify the JSON: '+E); } + var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"] + .createInstance(Components.interfaces.nsIScriptableUnicodeConverter); + converter.charset = "UTF-8"; + var converted = converter.ConvertToUnicode(data); + var obj; try { obj = JSON2js( converted ); } catch(E) { throw('Could not js-ify the JSON: '+E); } return obj; } catch(E) { this.error.sdump('D_ERROR',this._file.path + '\nutil.file.get_object(): ' + E); -- 2.11.0