diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index a83583d6b7..76b31dfa00 100644
--- a/django/forms/widgets.py
+++ b/django/forms/widgets.py
@@ -9,13 +9,13 @@ from collections import defaultdict
from graphlib import CycleError, TopologicalSorter
from itertools import chain
-from django.forms.utils import to_current_timezone
+from django.forms.utils import flatatt, to_current_timezone
from django.templatetags.static import static
from django.utils import formats
from django.utils.choices import normalize_choices
from django.utils.dates import MONTHS
from django.utils.formats import get_format
-from django.utils.html import conditional_escape, format_html, html_safe
+from django.utils.html import format_html, html_safe
from django.utils.regex_helper import _lazy_re_compile
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
@@ -83,7 +83,7 @@ class MediaAsset:
return format_html(
self.element_template,
path=self.path,
- attributes=mark_safe(" ".join(self.escaped_attributes)),
+ attributes=flatatt(self.attributes),
)
def __repr__(self):
@@ -99,18 +99,9 @@ class MediaAsset:
return self._path
return static(self._path)
- @property
- def escaped_attributes(self):
- """Render attributes as a key=value string or key-only if the value is True."""
- for key, value in self.attributes.items():
- if value is True:
- yield conditional_escape(key)
- elif value:
- yield format_html('{}="{}"', key, value)
-
class CSS(MediaAsset):
- element_template = ''
+ element_template = ''
def __init__(self, path, **attributes):
super().__init__(path, **attributes)
@@ -118,7 +109,7 @@ class CSS(MediaAsset):
class JS(MediaAsset):
- element_template = ''
@html_safe
diff --git a/tests/forms_tests/tests/test_media.py b/tests/forms_tests/tests/test_media.py
index 4b924b35b2..6bd88e19f4 100644
--- a/tests/forms_tests/tests/test_media.py
+++ b/tests/forms_tests/tests/test_media.py
@@ -57,12 +57,6 @@ class MediaAssetTestCase(SimpleTestCase):
asset = MediaAsset("http://media.other.com/path/to/css")
self.assertEqual(asset.path, "http://media.other.com/path/to/css")
- def test_escaped_attributes(self):
- asset = MediaAsset(
- "path/to/css", media="all", disabled=True, autocomplete=False
- )
- self.assertEqual(list(asset.escaped_attributes), ['media="all"', "disabled"])
-
@override_settings(
STATIC_URL="http://media.example.com/static/",