at master 1.6 kB view raw
1From 53f50bc0cee1cdfaf023ba65e1524b820cb7c18e Mon Sep 17 00:00:00 2001 2From: Matthias Kestenholz <mk@feinheit.ch> 3Date: Thu, 22 May 2025 10:37:20 +0200 4Subject: [PATCH] Disable bs4's multi valued attributes 5 6--- 7 compressor/parser/beautifulsoup.py | 12 ++++-------- 8 1 file changed, 4 insertions(+), 8 deletions(-) 9 10diff --git a/compressor/parser/beautifulsoup.py b/compressor/parser/beautifulsoup.py 11index 91897485..f673410e 100644 12--- a/compressor/parser/beautifulsoup.py 13+++ b/compressor/parser/beautifulsoup.py 14@@ -10,7 +10,9 @@ def __init__(self, content): 15 try: 16 from bs4 import BeautifulSoup 17 18- self.soup = BeautifulSoup(self.content, "html.parser") 19+ # Disable multi_valued_attributes 20+ # http://www.crummy.com/software/BeautifulSoup/bs4/doc/#multi-valued-attributes 21+ self.soup = BeautifulSoup(self.content, "html.parser", multi_valued_attributes={}) 22 except ImportError as err: 23 raise ImproperlyConfigured("Error while importing BeautifulSoup: %s" % err) 24 25@@ -21,13 +23,7 @@ def js_elems(self): 26 return self.soup.find_all("script") 27 28 def elem_attribs(self, elem): 29- attrs = dict(elem.attrs) 30- # hack around changed behaviour in bs4, it returns lists now instead of one string, see 31- # http://www.crummy.com/software/BeautifulSoup/bs4/doc/#multi-valued-attributes 32- for key, value in attrs.items(): 33- if type(value) is list: 34- attrs[key] = " ".join(value) 35- return attrs 36+ return elem.attrs 37 38 def elem_content(self, elem): 39 return elem.string