Skip to content

Commit e27fba2

Browse files
Fix invalid whitespace removal around star selector
1 parent 015341e commit e27fba2

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/css/tests.rs

+9
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,12 @@ fn check_weird_input() {
325325
assert_eq!(minify("*/**/=").unwrap().to_string(), "* =");
326326
assert_eq!(minify(r#"\-1"#).unwrap().to_string(), r#"\-1"#);
327327
}
328+
329+
#[test]
330+
fn check_space_after_star() {
331+
assert_eq!(minify("* .original").unwrap().to_string(), "* .original");
332+
assert_eq!(
333+
minify(".a * .original").unwrap().to_string(),
334+
".a * .original"
335+
);
336+
}

src/css/token.rs

+13
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ impl Token<'_> {
308308
matches!(*self, Token::SelectorElement(SelectorElement::Media(_)))
309309
}
310310

311+
fn is_a_selector_element(&self) -> bool {
312+
matches!(*self, Token::SelectorElement(_))
313+
}
314+
311315
fn is_a_license(&self) -> bool {
312316
matches!(*self, Token::License(_))
313317
}
@@ -619,6 +623,15 @@ fn clean_tokens(mut v: Vec<Token<'_>>) -> Vec<Token<'_>> {
619623
{
620624
// retain the space between keywords
621625
// and the space that disambiguates functions from keyword-plus-parens
626+
} else if v[previous_element_index].is_a_selector_element()
627+
&& matches!(v.get(i + 1), Some(Token::Char(ReservedChar::Star)))
628+
{
629+
// retain the space before `*` if it's preceded by a selector.
630+
} else if matches!(v[previous_element_index], Token::Char(ReservedChar::Star))
631+
&& v.get(i + 1)
632+
.is_some_and(|elem| elem.is_a_selector_element())
633+
{
634+
// retain the space after `*` if it's followed by a selector.
622635
} else if matches!(
623636
v[previous_element_index],
624637
Token::Char(

0 commit comments

Comments
 (0)