Skip to content

Commit 120419f

Browse files
committed
User a better escaping mechanism for HTML attributes
1 parent 1128fb4 commit 120419f

9 files changed

+18
-18
lines changed

templates/crud/action.html.twig

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
{% if 'a' == action.htmlElement %}
55
<a class="{{ isIncludedInDropdown|default(false) ? 'dropdown-item' }} {{ action.cssClass }}"
66
href="{{ action.linkUrl }}"
7-
{% for name, value in action.htmlAttributes %}{{ name }}="{{ (value.trans is defined ? value|trans : value)|e('html_attr') }}" {% endfor %}>
7+
{% for name, value in action.htmlAttributes %}{{ name }}="{{ (value.trans is defined ? value|trans : value)|e('html') }}" {% endfor %}>
88
{%- if action.icon %}<twig:ea:Icon name="{{ action.icon }}" class="action-icon" /> {% endif -%}
99
{%- if action.label is not empty -%}<span class="action-label">{{ action.label|trans|raw }}</span>{%- endif -%}
1010
</a>
1111
{% elseif 'button' == action.htmlElement %}
12-
<button class="{{ action.cssClass }}" {% for name, value in action.htmlAttributes %}{{ name }}="{{ (value.trans is defined ? value|trans : value)|e('html_attr') }}" {% endfor %}>
12+
<button class="{{ action.cssClass }}" {% for name, value in action.htmlAttributes %}{{ name }}="{{ (value.trans is defined ? value|trans : value)|e('html') }}" {% endfor %}>
1313
<span class="btn-label">
1414
{%- if action.icon %}<twig:ea:Icon name="{{ action.icon }}" /> {% endif -%}
1515
{%- if action.label is not empty -%}<span class="action-label">{{ action.label|trans|raw }}</span>{%- endif -%}

templates/crud/detail.html.twig

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
{% endblock %}
6464

6565
{% macro render_field_contents(entity, field) %}
66-
<div class="field-group {{ field.cssClass }}" {% for name, value in field.htmlAttributes %}{{ name }}="{{ value|e('html_attr') }}" {% endfor %}>
66+
<div class="field-group {{ field.cssClass }}" {% for name, value in field.htmlAttributes %}{{ name }}="{{ value|e('html') }}" {% endfor %}>
6767
{% if field.label is same as (false) %}
6868
{# a FALSE label value means that the field doesn't even display the <label> element;
6969
use an empty string to not display a label but keep the <label> element to not mess with the layout #}
@@ -73,7 +73,7 @@
7373
{%- if field.help is not empty -%}
7474
data-bs-toggle="tooltip" data-bs-placement="auto" data-bs-animation="false"
7575
data-bs-html="true" data-bs-custom-class="ea-detail-label-tooltip"
76-
data-bs-title="{{ field.help|trans|e('html_attr') }}"
76+
data-bs-title="{{ field.help|trans|e('html') }}"
7777
{%- endif -%}
7878
{%- endset -%}
7979

@@ -157,7 +157,7 @@
157157
{% set tab_id_option_name = constant('EasyCorp\\Bundle\\EasyAdminBundle\\Field\\FormField::OPTION_TAB_ID') %}
158158
{% set tab_is_active_option_name = constant('EasyCorp\\Bundle\\EasyAdminBundle\\Field\\FormField::OPTION_TAB_IS_ACTIVE') %}
159159

160-
<div id="{{ field.getCustomOption(tab_id_option_name) }}" class="tab-pane {% if field.getCustomOption(tab_is_active_option_name) %}active{% endif %} {{ field.cssClass }}" {% for key, value in field.getFormTypeOption('attr') %}{{ key }}="{{ value|e('html_attr') }}"{% endfor %}>
160+
<div id="{{ field.getCustomOption(tab_id_option_name) }}" class="tab-pane {% if field.getCustomOption(tab_is_active_option_name) %}active{% endif %} {{ field.cssClass }}" {% for key, value in field.getFormTypeOption('attr') %}{{ key }}="{{ value|e('html') }}"{% endfor %}>
161161
{% if field.help %}
162162
<div class="content-header-help tab-help">
163163
{{ field.help|trans(domain = ea.i18n.translationDomain)|raw }}
@@ -391,7 +391,7 @@
391391
{{ field.label|trans|raw }}
392392

393393
{% if field.help is not empty %}
394-
<a tabindex="0" class="data-help" data-bs-toggle="popover" data-bs-custom-class="ea-content-help-popover" data-bs-animation="true" data-bs-html="true" data-bs-placement="right" data-bs-trigger="focus" data-bs-content="{{ field.help|trans|e('html_attr') }}">
394+
<a tabindex="0" class="data-help" data-bs-toggle="popover" data-bs-custom-class="ea-content-help-popover" data-bs-animation="true" data-bs-html="true" data-bs-placement="right" data-bs-trigger="focus" data-bs-content="{{ field.help|trans|e('html') }}">
395395
<twig:ea:Icon name="internal:circle-info" />
396396
</a>
397397
{% endif %}

templates/crud/field/code_editor.html.twig

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
readonly
3232
style="{{ configuredHeight is null ? 'max-height: 500px;' : 'max-height: unset; height: ' ~ configuredHeight ~ 'px' }}"
3333
data-ea-code-editor-field="true"
34-
data-language="{{ field.customOptions.get('language')|e('html_attr') }}"
35-
data-tab-size="{{ field.customOptions.get('tabSize')|e('html_attr') }}"
34+
data-language="{{ field.customOptions.get('language')|e('html') }}"
35+
data-tab-size="{{ field.customOptions.get('tabSize')|e('html') }}"
3636
data-indent-with-tabs="{{ field.customOptions.get('indentWithTabs') ? 'true' : 'false' }}"
3737
data-show-line-numbers="{{ field.customOptions.get('showLineNumbers') ? 'true' : 'false' }}"
38-
data-number-of-rows="{{ field.customOptions.get('numOfRows')|e('html_attr') }}"
38+
data-number-of-rows="{{ field.customOptions.get('numOfRows')|e('html') }}"
3939
>
4040
{{- field.formattedValue|escape -}}
4141
</textarea>

templates/crud/form_theme.html.twig

+4-4
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@
670670
{% set tab_is_active_option_name = constant('EasyCorp\\Bundle\\EasyAdminBundle\\Field\\FormField::OPTION_TAB_IS_ACTIVE') %}
671671
{% set field = form.vars.ea_vars.field %}
672672

673-
<div id="{{ ea_tab_id }}" class="tab-pane {% if field.getCustomOption(tab_is_active_option_name) %}active{% endif %} {{ ea_css_class }}" {% for key, value in form.vars.attr %}{{ key }}={{ value|e('html_attr') }}{% endfor %}>
673+
<div id="{{ ea_tab_id }}" class="tab-pane {% if field.getCustomOption(tab_is_active_option_name) %}active{% endif %} {{ ea_css_class }}" {% for key, value in form.vars.attr %}{{ key }}={{ value|e('html') }}{% endfor %}>
674674
{% if ea_help %}
675675
<div class="content-header-help tab-help">
676676
{{ ea_help|trans(domain = ea.i18n.translationDomain)|raw }}
@@ -695,7 +695,7 @@
695695
<div class="filter-heading" id="filter-heading-{{ loop.index }}">
696696
<input type="checkbox" class="filter-checkbox" {% if field.vars.name in applied_filters %}checked{% endif %}>
697697
<a data-bs-toggle="collapse" href="#filter-content-{{ loop.index }}" aria-expanded="{{ field.vars.name in applied_filters ? 'true' : 'false' }}" aria-controls="filter-content-{{ loop.index }}"
698-
{% for name, value in field.vars.label_attr|default([]) %}{{ name }}="{{ value|e('html_attr') }}" {% endfor %}>
698+
{% for name, value in field.vars.label_attr|default([]) %}{{ name }}="{{ value|e('html') }}" {% endfor %}>
699699
{{ field.vars.label|default(field.vars.name|humanize)|trans(domain = ea.i18n.translationDomain) }}
700700
</a>
701701
</div>
@@ -873,8 +873,8 @@
873873
<div class="input-group">
874874
{{ block('form_widget') }}
875875
<button type="button" class="btn"
876-
data-icon-locked="{{ component('ea:Icon', {name: 'internal:lock'})|e('html_attr') }}"
877-
data-icon-unlocked="{{ component('ea:Icon', {name: 'internal:lock-open-solid'})|e('html_attr') }}">
876+
data-icon-locked="{{ component('ea:Icon', {name: 'internal:lock'})|e('html') }}"
877+
data-icon-unlocked="{{ component('ea:Icon', {name: 'internal:lock-open-solid'})|e('html') }}">
878878
<twig:ea:Icon name="internal:lock" />
879879
</button>
880880
</div>

templates/crud/index.html.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
{% for field in entity.fields %}
152152
{% set is_searchable = null == ea.crud.searchFields or field.property in ea.crud.searchFields %}
153153

154-
<td data-column="{{ field.property }}" data-label="{{ field.label|trans|e('html_attr') }}" class="{{ is_searchable ? 'searchable' }} {{ field.property == sort_field_name ? 'sorted' }} text-{{ field.textAlign }} {{ field.cssClass }}" dir="{{ ea.i18n.textDirection }}" {% for name, value in field.htmlAttributes %}{{ name }}="{{ value|e('html_attr') }}" {% endfor %}>
154+
<td data-column="{{ field.property }}" data-label="{{ field.label|trans|e('html') }}" class="{{ is_searchable ? 'searchable' }} {{ field.property == sort_field_name ? 'sorted' }} text-{{ field.textAlign }} {{ field.cssClass }}" dir="{{ ea.i18n.textDirection }}" {% for name, value in field.htmlAttributes %}{{ name }}="{{ value|e('html_attr') }}" {% endfor %}>
155155
{{ include(field.templatePath, { field: field, entity: entity }, with_context = false) }}
156156
</td>
157157
{% endfor %}

templates/includes/_css_assets.html.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
{% for css_asset in assets %}
33
{% set href = asset(css_asset.value, css_asset.packageName) %}
44
<link rel="stylesheet" href="{{ (css_asset.preload ? ea_call_function_if_exists('preload', href, { as: 'style', nopush: css_asset.nopush }))|default(href) }}"
5-
{%- for attr, value in css_asset.htmlAttributes %} {{ attr }}="{{ value|e('html_attr') }}"{% endfor %}>
5+
{%- for attr, value in css_asset.htmlAttributes %} {{ attr }}="{{ value|e('html') }}"{% endfor %}>
66
{% endfor %}

templates/includes/_js_assets.html.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
{% for js_asset in assets %}
33
{% set src = asset(js_asset.value, js_asset.packageName) %}
44
<script src="{{ (js_asset.preload ? ea_call_function_if_exists('preload', src, { as: 'script', nopush: js_asset.nopush }))|default(src) }}" {{ js_asset.async ? 'async' }} {{ js_asset.defer ? 'defer' }}
5-
{%- for attr, value in js_asset.htmlAttributes %} {{ attr }}="{{ value|e('html_attr') }}"{% endfor %}></script>
5+
{%- for attr, value in js_asset.htmlAttributes %} {{ attr }}="{{ value|e('html') }}"{% endfor %}></script>
66
{% endfor %}

templates/layout.html.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@
350350

351351
{% block content_help %}
352352
{% if has_help_message %}
353-
<a tabindex="0" class="content-header-help" data-bs-toggle="popover" data-bs-custom-class="ea-content-help-popover" data-bs-animation="true" data-bs-html="true" data-bs-placement="bottom" data-bs-trigger="focus" data-bs-content="{{ ea.crud.helpMessage|trans|e('html_attr') }}">
353+
<a tabindex="0" class="content-header-help" data-bs-toggle="popover" data-bs-custom-class="ea-content-help-popover" data-bs-animation="true" data-bs-html="true" data-bs-placement="bottom" data-bs-trigger="focus" data-bs-content="{{ ea.crud.helpMessage|trans|e('html') }}">
354354
<twig:ea:Icon name="internal:circle-info" />
355355
</a>
356356
{% endif %}

templates/menu.html.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
{% macro render_html_attributes(item) %}
3939
{% for attribute_name, attribute_value in item.htmlAttributes %}
40-
{{ attribute_name }}="{{ attribute_value|e('html_attr') }}"
40+
{{ attribute_name }}="{{ attribute_value|e('html') }}"
4141
{% endfor %}
4242
{% endmacro %}
4343

0 commit comments

Comments
 (0)