From: Galen Charlton Date: Fri, 11 Nov 2016 19:52:11 +0000 (-0500) Subject: LP#1641208: util.file no longer mangles UTF8 when writing JSON X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=a44049502364f851d52b9dec9cac99270ca2fede;p=evergreen%2Fpines.git LP#1641208: util.file no longer mangles UTF8 when writing JSON 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 --- 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);