[FIX] link_tracker: support any url
URLs with parameters were not correctly supported by the regular expression. For example, URLs with parameters were truncated before the '?'. This patch adds support for a wider range of URLs, and checks in a test that the parameters are correctly handled. closes odoo/odoo#39762 X-original-commit: 616e145635eac06a0a44ab3d899f4a9e707b3ba8 Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
This commit is contained in:
@@ -15,7 +15,7 @@ from odoo import models, fields, api, _
|
||||
|
||||
|
||||
URL_REGEX = r'(\bhref=[\'"](?!mailto:|tel:|sms:)([^\'"]+)[\'"])'
|
||||
TEXT_URL_REGEX = r'(https?:\/\/(www\.)?[a-zA-Z0-9@:%._\+~#=/-]{1,64})'
|
||||
TEXT_URL_REGEX = r'https?://[a-zA-Z0-9@:%._\+~#=/-]+(?:\?\S+)?'
|
||||
|
||||
|
||||
def VALIDATE_URL(url):
|
||||
@@ -151,8 +151,7 @@ class LinkTracker(models.Model):
|
||||
def _convert_links_text(self, body, vals, blacklist=None):
|
||||
shortened_schema = self.env['ir.config_parameter'].sudo().get_param('web.base.url') + '/r/'
|
||||
unsubscribe_schema = self.env['ir.config_parameter'].sudo().get_param('web.base.url') + '/sms/'
|
||||
for match in re.findall(TEXT_URL_REGEX, body):
|
||||
original_url = match[0]
|
||||
for original_url in re.findall(TEXT_URL_REGEX, body):
|
||||
# don't shorten already-shortened links or links towards unsubscribe page
|
||||
if original_url.startswith(shortened_schema) or original_url.startswith(unsubscribe_schema):
|
||||
continue
|
||||
|
||||
@@ -5,7 +5,7 @@ import re
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
TEXT_URL_REGEX = r'(https?:\/\/(www\.)?[a-zA-Z0-9@:%._\+~#=/-]{1,64})'
|
||||
TEXT_URL_REGEX = r'https?://[a-zA-Z0-9@:%._+~#=/-]+'
|
||||
|
||||
|
||||
class SmsSms(models.Model):
|
||||
@@ -25,8 +25,7 @@ class SmsSms(models.Model):
|
||||
continue
|
||||
|
||||
body = sms.body
|
||||
for match in re.findall(TEXT_URL_REGEX, body):
|
||||
url = match[0]
|
||||
for url in re.findall(TEXT_URL_REGEX, body):
|
||||
if url.startswith(shortened_schema):
|
||||
body = body.replace(url, url + '/s/%s' % sms.id)
|
||||
res[sms.id] = body
|
||||
|
||||
@@ -71,11 +71,16 @@ class TestSMSPost(test_mail_full_common.BaseFunctionalTest, sms_common.MockSMS,
|
||||
link = self.env['link.tracker'].search([('url', '=', link)])
|
||||
self.assertIn(link.short_url, new_body)
|
||||
|
||||
link = 'https://test.odoo.com/my/super_page'
|
||||
link = 'https://test.odoo.com/my/super_page?test[0]=42&toto=áâà#title3'
|
||||
self.env['link.tracker'].search([('url', '=', link)]).unlink()
|
||||
new_body = self.env['link.tracker']._convert_links_text('Welcome to %s !' % link, self.tracker_values)
|
||||
self.assertNotIn(link, new_body)
|
||||
self.assertLinkTracker(link, {'utm_campaign': self.utm_c.name, 'utm_medium': self.utm_m.name})
|
||||
self.assertLinkTracker(link, {
|
||||
'utm_campaign': self.utm_c.name,
|
||||
'utm_medium': self.utm_m.name,
|
||||
'test[0]': '42',
|
||||
'toto': 'áâà',
|
||||
})
|
||||
link = self.env['link.tracker'].search([('url', '=', link)])
|
||||
self.assertIn(link.short_url, new_body)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user