Skip to content

Commit 93a7fcb

Browse files
Merge pull request #111 from nifouprog/support-escaped-characters
Support escaped characters
2 parents 33d05d7 + 2605732 commit 93a7fcb

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/css/tests.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,16 @@ fn check_slash_slash() {
284284
assert_eq!(minify(s).expect("minify failed").to_string(), expected);
285285
}
286286

287+
#[test]
288+
fn check_escaped_characters() {
289+
let s = r#".before\:prose-headings\:content-\[\'\#\'\] :is(:where(h1,h2,h3,h4,h5,h6,th):not(:where([class~="not-prose"] *)))::before{
290+
--en-content: '#';
291+
content: var(--en-content);
292+
}"#;
293+
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);}"#;
294+
assert_eq!(minify(s).expect("minify failed").to_string(), expected);
295+
}
296+
287297
#[test]
288298
fn issue_80() {
289299
assert_eq!(

src/css/token.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub enum ReservedChar {
3030
Tilde,
3131
Dollar,
3232
Circumflex,
33+
Backslash,
3334
}
3435

3536
impl fmt::Display for ReservedChar {
@@ -61,6 +62,7 @@ impl fmt::Display for ReservedChar {
6162
ReservedChar::Tilde => '~',
6263
ReservedChar::Dollar => '$',
6364
ReservedChar::Circumflex => '^',
65+
ReservedChar::Backslash => '\\',
6466
}
6567
)
6668
}
@@ -94,6 +96,7 @@ impl TryFrom<char> for ReservedChar {
9496
'~' => Ok(ReservedChar::Tilde),
9597
'$' => Ok(ReservedChar::Dollar),
9698
'^' => Ok(ReservedChar::Circumflex),
99+
'\\' => Ok(ReservedChar::Backslash),
97100
_ => Err("Unknown reserved char"),
98101
}
99102
}
@@ -465,7 +468,16 @@ pub(super) fn tokenize(source: &str) -> Result<Tokens<'_>, &'static str> {
465468
|| v.last()
466469
.unwrap_or(&Token::Char(ReservedChar::Space))
467470
.is_a_media();
471+
468472
match c {
473+
ReservedChar::Backslash => {
474+
v.push(Token::Char(ReservedChar::Backslash));
475+
476+
if iterator.next().is_some() {
477+
pos += 1;
478+
v.push(Token::Other(&source[pos..pos + 1]));
479+
}
480+
}
469481
ReservedChar::Quote | ReservedChar::DoubleQuote => {
470482
if let Some(s) = get_string(source, &mut iterator, &mut pos, c) {
471483
v.push(s);

0 commit comments

Comments
 (0)