Skip to content

Commit

Permalink
Removed |safe filter from help text (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
smithdc1 committed Jun 16, 2021
1 parent 2d6e42a commit 52156bf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crispy_bootstrap5/templates/bootstrap5/layout/help_text.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% if field.help_text %}
{% if help_text_inline %}
<span id="hint_{{ field.auto_id }}" class="text-muted">{{ field.help_text|safe }}</span>
<span id="hint_{{ field.auto_id }}" class="text-muted">{{ field.help_text }}</span>
{% else %}
<small id="hint_{{ field.auto_id }}" class="form-text text-muted">{{ field.help_text|safe }}</small>
<small id="hint_{{ field.auto_id }}" class="form-text text-muted">{{ field.help_text }}</small>
{% endif %}
{% endif %}
9 changes: 9 additions & 0 deletions tests/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,12 @@ class GroupedChoiceForm(forms.Form):
widget=forms.CheckboxSelectMultiple, choices=choices
)
radio = forms.MultipleChoiceField(widget=forms.RadioSelect, choices=choices)


class HelpTextForm(forms.Form):
email = forms.EmailField(
label="email",
required=True,
widget=forms.TextInput(),
help_text="Insert your email<>&",
)
5 changes: 5 additions & 0 deletions tests/results/help_text_escape.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="mb-3" id="div_id_email"><label class="form-label requiredField" for="id_email">email<span
class="asteriskField">*</span></label><input class="form-control inputtext textInput textinput"
id="id_email" name="email" required type="text"><small class="form-text text-muted" id="hint_id_email">Insert
your email&lt;&gt;&amp;</small>
</div>
8 changes: 8 additions & 0 deletions tests/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
CrispyTestModel,
FileForm,
FileFormRequired,
HelpTextForm,
InputsForm,
LabelForm,
SampleForm,
Expand Down Expand Up @@ -640,3 +641,10 @@ def test_flat_attrs_safe():
)
form.helper.form_tag = False
assert parse_form(form) == parse_expected("flat_attrs.html")


def test_help_text_escape():
form = HelpTextForm()
form.helper = FormHelper()
form.helper.form_tag = False
assert parse_form(form) == parse_expected("help_text_escape.html")

0 comments on commit 52156bf

Please sign in to comment.