correctly parse quoted media queries

This commit is contained in:
Connor Skees 2020-07-09 13:43:27 -04:00
parent a813cab0d7
commit 0639a6ba2b
3 changed files with 26 additions and 4 deletions

View File

@ -1,6 +1,9 @@
use crate::{
error::SassResult,
utils::{is_name_start, peek_ident_no_interpolation, read_until_closing_paren},
utils::{
is_name_start, peek_ident_no_interpolation, read_until_closing_paren,
read_until_closing_quote,
},
{Cow, Token},
};
@ -61,13 +64,18 @@ impl<'a> Parser<'a> {
'>' | '<' | ':' | ')' => {
break;
}
'\'' | '"' => {
toks.push(tok);
self.toks.next();
toks.append(&mut read_until_closing_quote(self.toks, tok.kind)?);
}
_ => {
toks.push(tok);
self.toks.next();
}
}
}
self.parse_value_as_string_from_vec(toks)
self.parse_value_as_string_from_vec(toks, false)
}
pub(super) fn parse_media_query_list(&mut self) -> SassResult<String> {
@ -112,7 +120,7 @@ impl<'a> Parser<'a> {
todo!()
}
}
buf.push_str(&self.parse_value_as_string_from_vec(toks)?);
buf.push_str(&self.parse_value_as_string_from_vec(toks, true)?);
self.whitespace();
buf.push(')');

View File

@ -435,9 +435,14 @@ impl<'a> Parser<'a> {
pub fn parse_value_as_string_from_vec(
&mut self,
toks: Vec<Token>,
quoted: bool,
) -> SassResult<Cow<'static, str>> {
let value = self.parse_value_from_vec(toks)?;
if quoted {
value.node.to_css_string(value.span)
} else {
value.node.unquote().to_css_string(value.span)
}
}
pub fn whitespace(&mut self) -> bool {

View File

@ -54,3 +54,12 @@ test!(
"@media (color) {a {color: red;}}",
"@media (color) {\n a {\n color: red;\n }\n}\n"
);
test!(
quoted_colon_in_parens,
"@media screen and (\":\") {
a {
color: red;
}
}",
"@media screen and (:) {\n a {\n color: red;\n }\n}\n"
);