-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix urlize_quoted_hrefs() to make links again.
Also now correctly escapes JSON values for the web. fixes #5563. (cherry picked from commit 672a623)
- Loading branch information
Showing
3 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Browsable HREFs now have clickable links again. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import pytest | ||
from django.conf import settings | ||
|
||
from pulpcore.app.templatetags import pulp_urls | ||
|
||
pytestmark = pytest.mark.usefixtures("fake_domain") | ||
|
||
|
||
def test_urlize_quoted_hrefs_basic_url(): | ||
""" | ||
text starts with API_ROOT, defaults. Should be made clickable | ||
""" | ||
txt = settings.V3_API_ROOT + "foo/bar/" | ||
ret = pulp_urls.urlize_quoted_hrefs(txt) | ||
assert ret == f'<a href="{txt}" rel="nofollow">{txt}</a>' | ||
|
||
|
||
def test_urlize_quoted_hrefs_nofollow(): | ||
""" | ||
text starts with API_ROOT, defaults. Should be made clickable | ||
""" | ||
txt = settings.V3_API_ROOT + "foo/bar/" | ||
ret = pulp_urls.urlize_quoted_hrefs(txt, nofollow=False) | ||
assert ret == f'<a href="{txt}">{txt}</a>' | ||
|
||
|
||
def test_urlize_quoted_hrefs_trim(): | ||
""" | ||
text starts with API_ROOT, defaults. Should be made clickable | ||
""" | ||
txt = settings.V3_API_ROOT + "foo/bar/" | ||
trim_txt = txt[0] + "..." | ||
ret = pulp_urls.urlize_quoted_hrefs(txt, trim_url_limit=4) | ||
assert ret == f'<a href="{txt}" rel="nofollow">{trim_txt}</a>' | ||
|
||
|
||
def test_urlize_quoted_hrefs_basic_url_xss(): | ||
""" | ||
text starts with API_ROOT, includes XSS, defaults. Should be made clickable, escape XSS | ||
""" | ||
txt = settings.V3_API_ROOT + "foo/bar/<script>alert('ALERT!')</script>blech/" | ||
escapified_linked_text = ( | ||
'<a href="' + settings.V3_API_ROOT + "foo/bar/" | ||
'%3Cscript%3Ealert('ALERT!')%3C/script%3Eblech/" ' | ||
'rel="nofollow">' + settings.V3_API_ROOT + "foo/bar/<script>" | ||
"alert('ALERT!')</script>blech/</a>" | ||
) | ||
ret = pulp_urls.urlize_quoted_hrefs(txt) | ||
assert ret == escapified_linked_text | ||
|
||
|
||
def test_urlize_quoted_hrefs_basic_escape(): | ||
""" | ||
text contains XSS. Expect escaped | ||
""" | ||
txt = "foo/bar/<script>alert('ALERT!')</script>blech/" | ||
ret = pulp_urls.urlize_quoted_hrefs(txt) | ||
assert ret == "foo/bar/<script>alert('ALERT!')</script>blech/" |