Skip to content

Commit

Permalink
Safely encode koji build links
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Verga <[email protected]>
  • Loading branch information
mattiaverga committed Apr 29, 2023
1 parent 88e2bf6 commit 1e6e9a1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bodhi-server/bodhi/server/templates/update.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%inherit file="master.html"/>
<%namespace name="json" module="json"/>
<%
from urllib.parse import urljoin
from urllib.parse import quote, urljoin

from bodhi.server import models

Expand Down Expand Up @@ -603,7 +603,7 @@ <h4>How to install</h4>
<div class="flex-grow-1">
<%
koji_web_url = request.registry.settings.get('koji_web_url').strip('/') + '/'
build_url = urljoin(koji_web_url, 'search?terms='+build.nvr+'&type=build&match=exact')
build_url = urljoin(koji_web_url, 'search?terms='+quote(build.nvr)+'&type=build&match=exact')
%>
<a href="${build_url}" target="_blank">${build.nvr}</a>
</div>
Expand Down
11 changes: 11 additions & 0 deletions bodhi-server/tests/services/test_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -6084,6 +6084,17 @@ def test_frozen_release_html(self, update_status, release_state):
assert ('This update will not be pushed to stable until freeze is lifted '
f'from {release.long_name}.') not in resp

def test_koji_build_url_encoding(self):
"""Test HTML URL to koji build is correctly encoded."""
update = self.create_update(['hylafax+-7.0.3-1.fc17'])
self.db.commit()

resp = self.app.get(f'/updates/{update.alias}', headers={'Accept': 'text/html'})

assert 'text/html' in resp.headers['Content-Type']
assert ('search?terms=hylafax%2B-7.0.3-1.fc17&amp;type=build&amp;match=exact" '
'target="_blank">hylafax+-7.0.3-1.fc17</a>') in resp


class TestWaiveTestResults(BasePyTestCase):
"""
Expand Down
1 change: 1 addition & 0 deletions news/5272.bug
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Link to Koji builds are now correctly encoded

0 comments on commit 1e6e9a1

Please sign in to comment.