From 6638c9bb44dca2def13f68baf0f3381fa401b8d5 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 6 Jan 2021 11:36:28 -0800 Subject: [PATCH] Handles query params in urls --- bookwyrm/outgoing.py | 3 ++- bookwyrm/tests/test_outgoing.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/bookwyrm/outgoing.py b/bookwyrm/outgoing.py index b438f5d18..bc170748a 100644 --- a/bookwyrm/outgoing.py +++ b/bookwyrm/outgoing.py @@ -296,7 +296,8 @@ def find_mentions(content): def format_links(content): ''' detect and format links ''' return re.sub( - r'([^(href=")]|^)(https?:\/\/(%s([\w\.\-_\/])*))' % regex.domain, + r'([^(href=")]|^)(https?:\/\/(%s([\w\.\-_\/+&\?=:;,])*))' % \ + regex.domain, r'\g<1>\g<3>', content) diff --git a/bookwyrm/tests/test_outgoing.py b/bookwyrm/tests/test_outgoing.py index 498b43d9c..ba0d7d7de 100644 --- a/bookwyrm/tests/test_outgoing.py +++ b/bookwyrm/tests/test_outgoing.py @@ -503,3 +503,9 @@ class Outgoing(TestCase): '' \ 'archive.org/details/dli.granth.72113/page/n25/mode/2up' \ % url) + url = 'https://openlibrary.org/search' \ + '?q=arkady+strugatsky&mode=everything' + self.assertEqual( + outgoing.format_links(url), + 'openlibrary.org/search' \ + '?q=arkady+strugatsky&mode=everything' % url)