[FIX] web_editor, translate: xml translate encoding

lxml.HTMLParser detect the content encoding by itself if not specified.

in the issue leading to this fix, content in a mail with u'\xa4'
( ) was transformed intto u'\xc2\xa4' ( ) since HTMLParser
selected the wrong encoding (latin-1 instead of utf-8 for example).

this commit specify the known encoding and revert 3d00c210f which was
another attempt at this issue.
This commit is contained in:
Nicolas Lempereur
2015-09-03 10:21:20 +02:00
parent e6b7be9bab
commit c32ea33632
2 changed files with 2 additions and 10 deletions
+1 -9
View File
@@ -307,15 +307,7 @@ var FieldTextHtml = widget.extend({
return this.editor.save();
} else if (this._dirty_flag && this.editor && this.editor.buildingBlock) {
this.editor.buildingBlock.clean_for_save();
// escape text nodes for xml saving
var $escaped_el = this.$content.clone();
$escaped_el.find('*').addBack().not('script,style').contents().each(function(){
if(this.nodeType == 3) {
this.nodeValue = _.escape(this.nodeValue);
}
});
this.internal_set_value( $escaped_el.html() );
this.internal_set_value( this.$content.html() );
}
},
destroy: function () {
+1 -1
View File
@@ -271,7 +271,7 @@ def xml_translate(callback, value):
return trans.get_done()
except etree.ParseError:
wrapped = "<div>%s</div>" % encode(value)
root = etree.fromstring(wrapped, etree.HTMLParser())
root = etree.fromstring(wrapped, etree.HTMLParser(encoding='utf-8'))
# html > body > div
trans.process(root[0][0])
return trans.get_done()[5:-6]