diff --git a/addons/website_forum/models/forum_post.py b/addons/website_forum/models/forum_post.py index e147337ba1a..fadd3ec763f 100644 --- a/addons/website_forum/models/forum_post.py +++ b/addons/website_forum/models/forum_post.py @@ -426,8 +426,10 @@ class Post(models.Model): forum = self.env['forum.forum'].browse(forum_id) if content and self.env.user.karma < forum.karma_dofollow: for match in re.findall(r'', content): - match = re.escape(match) # replace parenthesis or special char in regex - content = re.sub(match, match[:3] + 'rel="nofollow" ' + match[3:], content) + escaped_match = re.escape(match) # replace parenthesis or special char in regex + url_match = re.match(r'^.*href="(.*)".*', match) # extracting the link allows to rebuild a clean link tag + url = url_match.group(1) + content = re.sub(escaped_match, f'', content) if self.env.user.karma < forum.karma_editor: filter_regexp = r'()|(]*?href[^>]*?>)|(<[a-z|A-Z]+[^>]*style\s*=\s*[\'"][^\'"]*\s*background[^:]*:[^url;]*url)' diff --git a/addons/website_forum/tests/test_forum_internals.py b/addons/website_forum/tests/test_forum_internals.py index 3a4575af2a2..772edad458e 100644 --- a/addons/website_forum/tests/test_forum_internals.py +++ b/addons/website_forum/tests/test_forum_internals.py @@ -145,3 +145,14 @@ class TestTags(TestForumCommon): self.assertEqual(self.base_forum.tag_most_used_ids, self.base_forum.tag_ids[:MOST_USED_TAGS_COUNT]) self.assertEqual(self.base_forum.tag_unused_ids, self.env['forum.tag']) + + def test_forum_post_link(self): + content = 'This is a test link: test Let make sure it works.' + self.user_portal.karma = 50 + with self.with_user(self.user_portal.login): + post = self.env['forum.post'].create({ + 'name': "Post Forum test", + 'content': content, + 'forum_id': self.forum.id, + }) + self.assertEqual(post.content, '

This is a test link: test Let make sure it works.

')