diff --git a/src/css/tests.rs b/src/css/tests.rs index 2a3459e..5a55cbf 100644 --- a/src/css/tests.rs +++ b/src/css/tests.rs @@ -284,6 +284,16 @@ fn check_slash_slash() { assert_eq!(minify(s).expect("minify failed").to_string(), expected); } +#[test] +fn check_escaped_characters() { + let s = r#".before\:prose-headings\:content-\[\'\#\'\] :is(:where(h1,h2,h3,h4,h5,h6,th):not(:where([class~="not-prose"] *)))::before{ + --en-content: '#'; + content: var(--en-content); +}"#; + let expected = r#".before\:prose-headings\:content-\[\'\#\'\] :is(:where(h1,h2,h3,h4,h5,h6,th):not(:where([class~="not-prose"] *)))::before{--en-content:'#';content:var(--en-content);}"#; + assert_eq!(minify(s).expect("minify failed").to_string(), expected); +} + #[test] fn issue_80() { assert_eq!( diff --git a/src/css/token.rs b/src/css/token.rs index 467bed0..7e443e8 100644 --- a/src/css/token.rs +++ b/src/css/token.rs @@ -30,6 +30,7 @@ pub enum ReservedChar { Tilde, Dollar, Circumflex, + Backslash, } impl fmt::Display for ReservedChar { @@ -61,6 +62,7 @@ impl fmt::Display for ReservedChar { ReservedChar::Tilde => '~', ReservedChar::Dollar => '$', ReservedChar::Circumflex => '^', + ReservedChar::Backslash => '\\', } ) } @@ -94,6 +96,7 @@ impl TryFrom for ReservedChar { '~' => Ok(ReservedChar::Tilde), '$' => Ok(ReservedChar::Dollar), '^' => Ok(ReservedChar::Circumflex), + '\\' => Ok(ReservedChar::Backslash), _ => Err("Unknown reserved char"), } } @@ -465,7 +468,16 @@ pub(super) fn tokenize(source: &str) -> Result, &'static str> { || v.last() .unwrap_or(&Token::Char(ReservedChar::Space)) .is_a_media(); + match c { + ReservedChar::Backslash => { + v.push(Token::Char(ReservedChar::Backslash)); + + if iterator.next().is_some() { + pos += 1; + v.push(Token::Other(&source[pos..pos + 1])); + } + } ReservedChar::Quote | ReservedChar::DoubleQuote => { if let Some(s) = get_string(source, &mut iterator, &mut pos, c) { v.push(s);