From e2ff2fd29bba2c124dcc5f4012ddcc7d23e20f80 Mon Sep 17 00:00:00 2001 From: Christophe Monniez Date: Mon, 25 Apr 2022 09:06:55 +0000 Subject: [PATCH] [FIX] link_tracker, pos_mercury: use unescape from html As werkzeug.utils.unescape is deprecated in werkzeug 2.0 and the markupsafe version of unescape just uses the built-in html.unescape [0], we can use directly the same built-in method. [0] pallets/markupsafe@c35603a9037d3dd679732089ecd1084abc6e8cb7 Part-of: odoo/odoo#91927 --- addons/link_tracker/models/mail_render_mixin.py | 7 ++++--- addons/pos_mercury/models/pos_mercury_transaction.py | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/link_tracker/models/mail_render_mixin.py b/addons/link_tracker/models/mail_render_mixin.py index 2c7fa9c5e09..f7ff2d4548b 100644 --- a/addons/link_tracker/models/mail_render_mixin.py +++ b/addons/link_tracker/models/mail_render_mixin.py @@ -4,7 +4,8 @@ import re import markupsafe -from werkzeug import urls, utils +from html import unescape +from werkzeug import urls from odoo import api, models, tools @@ -45,7 +46,7 @@ class MailRenderMixin(models.AbstractModel): continue label = (match[3] or '').strip() - create_vals = dict(link_tracker_vals, url=utils.unescape(long_url), label=utils.unescape(label)) + create_vals = dict(link_tracker_vals, url=unescape(long_url), label=unescape(label)) link = self.env['link.tracker'].search_or_create(create_vals) if link.short_url: # `str` manipulation required to support replacing "&" characters, common in urls @@ -75,7 +76,7 @@ class MailRenderMixin(models.AbstractModel): if blacklist and any(item in parsed.path for item in blacklist): continue - create_vals = dict(link_tracker_vals, url=utils.unescape(original_url)) + create_vals = dict(link_tracker_vals, url=unescape(original_url)) link = self.env['link.tracker'].search_or_create(create_vals) if link.short_url: # Ensures we only replace the same link and not a subpart of a longer one, multiple times if applicable diff --git a/addons/pos_mercury/models/pos_mercury_transaction.py b/addons/pos_mercury/models/pos_mercury_transaction.py index 7ce0811d714..bb1ca421c0b 100644 --- a/addons/pos_mercury/models/pos_mercury_transaction.py +++ b/addons/pos_mercury/models/pos_mercury_transaction.py @@ -4,7 +4,8 @@ from datetime import date, timedelta import requests -import werkzeug + +from html import unescape from odoo import models, api, service from odoo.tools.translate import _ @@ -69,7 +70,7 @@ class MercuryTransaction(models.Model): try: r = requests.post(url, data=xml_transaction, headers=headers, timeout=65) r.raise_for_status() - response = werkzeug.utils.unescape(r.content.decode()) + response = unescape(r.content.decode()) except Exception: response = "timeout"