Skip to content

Commit dfc76dc

Browse files
gerrod3cursoragent
authored andcommitted
Fix content app directory listing links with colons in base_path
closes #6955 Assisted-by: Claude (Cursor) Made-with: Cursor Co-authored-by: Cursor <cursoragent@cursor.com> (cherry picked from commit e8937bc)
1 parent ea53f1b commit dfc76dc

5 files changed

Lines changed: 23 additions & 10 deletions

File tree

CHANGES/6955.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed content app directory listing generating broken links when distribution base paths contain colons.

pulpcore/content/handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ def render_html(directory_list, path="", dates=None, sizes=None):
567567
{% else -%}
568568
{% set size = "" -%}
569569
{% endif -%}
570-
<a href="{{ name|e }}">{{ name|e }}</a>{% for number in range(100 - name|e|length) %} """
570+
<a href="./{{ name|e }}">{{ name|e }}</a>{% for number in range(100 - name|e|length) %} """
571571
"""{% endfor %}{{ date }} {{ size }}
572572
{% endfor -%}
573573
</pre><hr></body>

pulpcore/tests/functional/api/using_plugin/test_content_directory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ def test_hidden_distros(file_distribution_factory, pulp_content_url, http_get):
99
content = http_get(pulp_content_url).decode("utf-8")
1010

1111
for d in visible:
12-
assert content.count(f'a href="{d.base_path}/"') == 1
12+
assert content.count(f'a href="./{d.base_path}/"') == 1
1313
for d in hidden:
14-
assert content.count(f'a href="{d.base_path}/"') == 0
14+
assert content.count(f'a href="./{d.base_path}/"') == 0
1515

1616

1717
@pytest.mark.parallel
@@ -39,7 +39,7 @@ def test_zero_byte_file_listing(
3939
monitor_task(task)
4040
distribution = file_distribution_factory(repository=file_repo_with_auto_publish.pulp_href)
4141
response = http_get(distribution_base_url(distribution.base_url))
42-
z_line = [i for i in response.decode("utf-8").split("\n") if i.startswith('<a href="zero">')]
42+
z_line = [i for i in response.decode("utf-8").split("\n") if i.startswith('<a href="./zero">')]
4343
assert len(z_line) == 1
4444
assert z_line[0].endswith("0 Bytes")
4545

pulpcore/tests/functional/api/using_plugin/test_content_path.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ def test_content_directory_listing(
4545
if pulp_settings.DOMAIN_ENABLED:
4646
base_url = urljoin(base_url, "default/")
4747
response = http_get(base_url).decode("utf-8")
48-
assert response.count(f'a href="{base_path}/"') == 1
48+
assert response.count(f'a href="./{base_path}/"') == 1
4949
assert response.count('a href="../"') == 0
5050

5151
url = urljoin(base_url, base_path + "/")
5252
response = http_get(url).decode("utf-8")
53-
assert response.count('a href="foo1/"') == 1
54-
assert response.count('a href="foo2/"') == (0 if HIDE_GUARDED_DISTRIBUTIONS else 1)
55-
assert response.count('a href="boo1/"') == 1
56-
assert response.count('a href="boo2/"') == (0 if HIDE_GUARDED_DISTRIBUTIONS else 1)
53+
assert response.count('a href="./foo1/"') == 1
54+
assert response.count('a href="./foo2/"') == (0 if HIDE_GUARDED_DISTRIBUTIONS else 1)
55+
assert response.count('a href="./boo1/"') == 1
56+
assert response.count('a href="./boo2/"') == (0 if HIDE_GUARDED_DISTRIBUTIONS else 1)
5757
assert response.count('a href="../"') == 1
5858

5959
response = http_get(urljoin(url, "boo1/")).decode("utf-8")
60-
assert response.count('a href="foo1/"') == 1
60+
assert response.count('a href="./foo1/"') == 1
6161

6262
# Assert that not using a trailing slash on the root returns a 301
6363
base_url = urljoin(

pulpcore/tests/unit/content/test_handler.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,18 @@ async def test_app_status_fixture_is_reusable(app_status, repeat):
574574
assert app_status
575575

576576

577+
def test_render_html_colon_in_name():
578+
"""Links with colons in the name should use './' prefix to avoid being treated as a scheme."""
579+
html = Handler.render_html(["copr-pull-requests:pr:3825/"])
580+
assert '<a href="./copr-pull-requests:pr:3825/">copr-pull-requests:pr:3825/</a>' in html
581+
582+
583+
def test_render_html_normal_name():
584+
"""Normal directory names should also get the './' prefix."""
585+
html = Handler.render_html(["simple-dir/"])
586+
assert '<a href="./simple-dir/">simple-dir/</a>' in html
587+
588+
577589
@pytest.mark.asyncio
578590
@pytest.mark.django_db
579591
async def test_async_pull_through_add(ca1, monkeypatch, app_status):

0 commit comments

Comments
 (0)