Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9345819
D7213.id26154.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D7213.id26154.diff
View Options
diff --git a/swh/web/common/swh_templatetags.py b/swh/web/common/swh_templatetags.py
--- a/swh/web/common/swh_templatetags.py
+++ b/swh/web/common/swh_templatetags.py
@@ -57,14 +57,10 @@
The text as is otherwise.
"""
- links = text.split(",")
- ret = ""
- for i, link in enumerate(links):
- ret += re.sub(r"<(http.*)>", r'<<a href="\1">\1</a>>', link)
- # add one link per line and align them
- if i != len(links) - 1:
- ret += "\n "
- return ret
+ ret = re.sub(
+ r'<(http[^<>]+)>; rel="([^,]+)"', r'<<a href="\1">\1</a>>; rel="\2"\n', text
+ ).replace("\n,", "\n")
+ return ret[:-1]
@register.filter
diff --git a/swh/web/tests/common/test_templatetags.py b/swh/web/tests/common/test_templatetags.py
--- a/swh/web/tests/common/test_templatetags.py
+++ b/swh/web/tests/common/test_templatetags.py
@@ -3,6 +3,9 @@
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
+import pytest
+
+from swh.web.api.apiresponse import compute_link_header
from swh.web.common.swh_templatetags import (
docstring_display,
urlize_header_links,
@@ -24,19 +27,30 @@
assert urlize_links_and_mails(email) == expected_content
-def test_urlize_header_links():
+@pytest.mark.parametrize(
+ "next_link, prev_link",
+ [
+ ("https://example.org/api/1/abc/", "https://example.org/api/1/def/"),
+ ("https://example.org/api/1/0,5/", "https://example.org/api/1/5,10/"),
+ ],
+)
+def test_urlize_header_links(next_link, prev_link):
- next_link = "https://example.com/api/1/abc/"
- prev_link = "https://example.com/api/1/def/"
+ link_header = f'<{next_link}>; rel="next",<{prev_link}>; rel="previous"'
- content = f'<{next_link}>; rel="next"\n<{prev_link}>; rel="prev"'
+ assert (
+ link_header
+ == compute_link_header(
+ {"headers": {"link-next": next_link, "link-prev": prev_link}}, options={}
+ )["Link"]
+ )
expected_content = (
f'<<a href="{next_link}">{next_link}</a>>; rel="next"\n'
- f'<<a href="{prev_link}">{prev_link}</a>>; rel="prev"'
+ f'<<a href="{prev_link}">{prev_link}</a>>; rel="previous"'
)
- assert urlize_header_links(content) == expected_content
+ assert urlize_header_links(link_header) == expected_content
def test_docstring_display():
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jul 3, 3:32 PM (1 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3219001
Attached To
D7213: common/swh_templatetags: Fix parsing issue in urlize_header_links
Event Timeline
Log In to Comment