diff options
| author | Xavier Morel <xmo@odoo.com> | 2017-05-12 17:14:52 +0200 |
|---|---|---|
| committer | Xavier Morel <xmo@odoo.com> | 2017-05-15 12:26:31 +0200 |
| commit | e2f1af78c465916551f12419f37d4e63a6cfd7f2 (patch) | |
| tree | 64b5e6a05831bb5db4e32d241d90eedc2bedda7e /odoo/tools/mail.py | |
| parent | 5617d4614b4644f0eaf2feb402f0066f260200c8 (diff) | |
[FIX] P3: remove cgi.escape uses
cgi.escape is unsafe (quote=False by default) and deprecated in Python
3. We already have an openerp.tools.misc.html_escape version which
forwards to the (modern and safe) werkzeug.utils.escape, just use that
everywhere, and convert extant uses of werkzeug.utils.escape to
utils.html_escape as well so that we do the same thing everywhere.
Diffstat (limited to 'odoo/tools/mail.py')
| -rw-r--r-- | odoo/tools/mail.py | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/odoo/tools/mail.py b/odoo/tools/mail.py index 9689512df00..f3396f9137b 100644 --- a/odoo/tools/mail.py +++ b/odoo/tools/mail.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -import cgi import logging import lxml.html.clean as clean import random @@ -16,7 +15,7 @@ from lxml import etree import odoo from odoo.loglevels import ustr -from odoo.tools import pycompat +from odoo.tools import pycompat, misc _logger = logging.getLogger(__name__) @@ -178,10 +177,10 @@ def html_sanitize(src, silent=True, sanitize_tags=True, sanitize_attributes=Fals part = re.compile(r"(<(([^a<>]|a[^<>\s])[^<>]*)@[^<>]+>)", re.IGNORECASE | re.DOTALL) # remove results containing cite="mid:email_like@address" (ex: blockquote cite) # cite_except = re.compile(r"^((?!cite[\s]*=['\"]).)*$", re.IGNORECASE) - src = part.sub(lambda m: ('cite=' not in m.group(1) and 'alt=' not in m.group(1)) and cgi.escape(m.group(1)) or m.group(1), src) + src = part.sub(lambda m: ('cite=' not in m.group(1) and 'alt=' not in m.group(1)) and misc.html_escape(m.group(1)) or m.group(1), src) # html encode mako tags <% ... %> to decode them later and keep them alive, otherwise they are stripped by the cleaner - src = src.replace('<%', cgi.escape('<%')) - src = src.replace('%>', cgi.escape('%>')) + src = src.replace('<%', misc.html_escape('<%')) + src = src.replace('%>', misc.html_escape('%>')) kwargs = { 'page_structure': True, @@ -334,7 +333,7 @@ def html2plaintext(html, body_id=None, encoding='utf-8'): def plaintext2html(text, container_tag=False): """ Convert plaintext into html. Content of the text is escaped to manage - html entities, using cgi.escape(). + html entities, using misc.html_escape(). - all \n,\r are replaced by <br /> - enclose content into <p> - convert url into clickable link @@ -343,7 +342,7 @@ def plaintext2html(text, container_tag=False): :param string container_tag: container of the html; by default the content is embedded into a <div> """ - text = cgi.escape(ustr(text)) + text = misc.html_escape(ustr(text)) # 1. replace \n and \r text = text.replace('\n', '<br/>') |
