fix(html/minifier): Avoid removing id with spaces (#4786)

This commit is contained in:
Alexander Akait 2022-05-26 09:13:39 +03:00 committed by GitHub
parent e9559e7d13
commit c35cb598f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 5 deletions

View File

@ -368,8 +368,6 @@ impl VisitMut for Minifier {
return true;
}
let is_empty_value = (&*attribute.value.as_ref().unwrap()).trim().is_empty();
if self.is_default_attribute_value(
n.namespace,
&n.tag_name,
@ -386,12 +384,16 @@ impl VisitMut for Minifier {
}
_ => attribute.value.as_ref().unwrap(),
},
) || (matches!(&*attribute.name, "id" | "class" | "style") && is_empty_value)
{
) {
return false;
}
if self.is_event_handler_attribute(&attribute.name) && is_empty_value {
let value = &*attribute.value.as_ref().unwrap();
if (matches!(&*attribute.name, "id") && value.is_empty())
|| (matches!(&*attribute.name, "class" | "style") && value.trim().is_empty())
|| self.is_event_handler_attribute(&attribute.name) && value.trim().is_empty()
{
return false;
}

View File

@ -0,0 +1,20 @@
<!doctype html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<div class=" ">test</div>
<div class="">test</div>
<div id=" ">test</div>
<div id="">test</div>
<div style=" ">test</div>
<div style="">test</div>
<div onblur="javascript:alert('test')">test</div>
<div onblur="">test</div>
<div onblur="#">test</div>
</body>
</html>

View File

@ -0,0 +1,15 @@
<!doctype html><html lang=en><title>Document</title></head>
<body>
<div>test</div>
<div>test</div>
<div id=" ">test</div>
<div>test</div>
<div>test</div>
<div>test</div>
<div onblur="alert('test')">test</div>
<div>test</div>
<div onblur=#>test</div>