From dccecaf11f575db1f9b58ee1df334cd89bdd8479 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Fri, 13 Nov 2015 16:57:40 +0100 Subject: [PATCH] [IMP] web_editor: use unicode number for FontAwesome controller In some non-usual circumstances, using unicode in controllers can lead to issue. For example on a terminal using C encoding (instead of the mighty UTF-8) werkzeug might use sys.getfilesystemencoding to encode the request URL which will fail with UTF-8 inside. This commit change the URL character of the font awesome controller to UTF-8, but keep the old way since every sent mail might still use it. There is the overlap of character 0 to 9 which are overidden in this commit by unicode code 0 to 9, but these were not used in font-awesome anyway (or these are not even visible ASCII characters). closes #9572 --- addons/web_editor/controllers/main.py | 10 +++++++--- addons/web_editor/static/src/js/transcoder.js | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/addons/web_editor/controllers/main.py b/addons/web_editor/controllers/main.py index 24fb6064dcb..bd4fd66bcb8 100644 --- a/addons/web_editor/controllers/main.py +++ b/addons/web_editor/controllers/main.py @@ -74,9 +74,10 @@ class Web_Editor(http.Controller): '/web_editor/font_to_img////', ], type='http', auth="none") def export_icon_to_png(self, icon, color='#000', size=100, alpha=255, font='/web/static/lib/fontawesome/fonts/fontawesome-webfont.ttf'): - """ This method converts FontAwesom pictograms to Images and is Used only - for mass mailing becuase custom fonts are not supported in mail. - :param icon : character from FontAwesom cheatsheet + """ This method converts an unicode character to an image (using Font + Awesome font by default) and is used only for mass mailing because + custom fonts are not supported in mail. + :param icon : decimal encoding of unicode character :param color : RGB code of the color :param size : Pixels in integer :param alpha : transparency of the image from 0 to 255 @@ -88,6 +89,9 @@ class Web_Editor(http.Controller): addons_path = http.addons_manifest['web']['addons_path'] font_obj = ImageFont.truetype(addons_path + font, size) + # if received character is not a number, keep old behaviour (icon is character) + icon = unichr(int(icon)) if icon.isdigit() else icon + # Determine the dimensions of the icon image = Image.new("RGBA", (size, size), color=(0, 0, 0, 0)) draw = ImageDraw.Draw(image) diff --git a/addons/web_editor/static/src/js/transcoder.js b/addons/web_editor/static/src/js/transcoder.js index bd7848d2e97..4fd512f883a 100644 --- a/addons/web_editor/static/src/js/transcoder.js +++ b/addons/web_editor/static/src/js/transcoder.js @@ -107,7 +107,7 @@ var font_to_img = function ($editable) { }); if (content) { var color = $font.css("color").replace(/\s/g, ''); - var src = _.str.sprintf('/web_editor/font_to_img/%s/%s/'+$font.height(), window.encodeURI(content), window.encodeURI(color)); + var src = _.str.sprintf('/web_editor/font_to_img/%s/%s/'+$font.height(), content.charCodeAt(0), window.encodeURI(color)); var $img = $("").attr("src", src) .attr("data-class", $font.attr("class")) .attr("class", $font.attr("class").replace(new RegExp("(^|\\s+)" + icon + "(-[^\\s]+)?", "gi"), '')) // remove inline font-awsome style