[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@c35603a903

Part-of: odoo/odoo#91927
This commit is contained in:
Christophe Monniez
2022-05-23 08:29:54 +02:00
parent ba1724732c
commit e2ff2fd29b
2 changed files with 7 additions and 5 deletions
@@ -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
@@ -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"