[FIX] base: render with page-break => ok encoding

If we have eg. a report with a page break (eg. `Print On New Page`
enabled on a financial report section) the encoding is broken.

The reason is that lxml.html fragments_fromstring function accepts text
string (OK in unicode) or bytestring => the encoding will be guessed (by
chardet library) if guess_charset argument is set to true.

So since we do not pass guess_charset option, the encoding is not
recognized.

In this changeset, we give a text string to the fragments_fromstring
function since it seems that all our input should be in UTF-8.

note: lxml.html itself uses html5lib.HTMLParser parseFragment that takes
a charset argument, but there is no interface through
fragments_fromstring to specify the charset.

opw-2146715
closes #41255

closes odoo/odoo#41289

X-original-commit: 1d3d517aad08887970e4ba2d9290e260faacae2d
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
This commit is contained in:
Nicolas Lempereur
2019-12-03 12:41:39 +00:00
parent 9830d924e9
commit 7c4628b1f4
+1 -1
View File
@@ -60,7 +60,7 @@ class IrQWeb(models.AbstractModel, QWeb):
if b'data-pagebreak=' not in result:
return result
fragments = html.fragments_fromstring(result)
fragments = html.fragments_fromstring(result.decode('utf-8'))
for fragment in fragments:
for row in fragment.iterfind('.//tr[@data-pagebreak]'):