Skip to content

Commit d702daf

Browse files
authored
Fix an issue with urlize_target_blank when the URL contains curly braces (#292)
Signed-off-by: tdruez <[email protected]>
1 parent 30aa2eb commit d702daf

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ Release notes
123123
- Refine the way the PURL fragments are handled in searches.
124124
https://github.com/aboutcode-org/dejacode/issues/286
125125

126+
- Fix an issue with ``urlize_target_blank`` when the URL contains curly braces.
127+
126128
### Version 5.2.1
127129

128130
- Fix the models documentation navigation.

component_catalog/templates/component_catalog/tables/package_list_table.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{% load i18n %}
22
{% load inject_preserved_filters from dje_tags %}
3-
{% load urlize_target_blank from dje_tags %}
43
{% load naturaltime_short from dje_tags %}
54
<table id="object-list-table" class="table table-bordered table-striped table-md table-fixed-layout text-break packages-table">
65
{% if form or add_to_component_form %}

dje/templatetags/dje_tags.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from django.utils.html import format_html
2222
from django.utils.html import urlize as _urlize
2323
from django.utils.http import urlencode
24+
from django.utils.safestring import mark_safe
2425

2526
register = Library()
2627

@@ -139,7 +140,7 @@ def urlize_target_blank(value, autoescape=True):
139140
else:
140141
link = _urlize(value, nofollow=True, autoescape=autoescape)
141142
link = link.replace("<a", '<a target="_blank"')
142-
return format_html(link)
143+
return mark_safe(link)
143144

144145

145146
@register.filter

dje/tests/test_templatetags.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ def test_dje_templatetags_urlize_target_blank_template_tag(self):
3737
'<a target="_blank" href="ftp://domain.com" rel="noreferrer nofollow">'
3838
"ftp://domain.com</a>",
3939
),
40+
(
41+
"https://repo1.maven.org/maven2/{0/group_id}/{0.version}.jar",
42+
'<a target="_blank" href="https://repo1.maven.org/maven2/%7B0/'
43+
'group_id%7D/%7B0.version%7D.jar" rel="nofollow">'
44+
"https://repo1.maven.org/maven2/{0/group_id}/{0.version}.jar</a>",
45+
),
4046
]
4147

4248
for url, expected in inputs:

0 commit comments

Comments
 (0)