allow escaped non-alphanumeric bytes in media queries

This commit is contained in:
Connor Skees 2022-12-28 17:09:55 -05:00
parent e5da366fac
commit 9b6623190d
5 changed files with 20 additions and 4 deletions

View File

@ -96,6 +96,7 @@ pub(crate) struct AstEach {
#[derive(Debug, Clone)]
pub(crate) struct AstMedia {
pub query: Interpolation,
pub query_span: Span,
pub body: Vec<AstStmt>,
pub span: Span,
}

View File

@ -1222,10 +1222,14 @@ impl<'a> Visitor<'a> {
Some(queries)
}
fn visit_media_queries(&mut self, queries: Interpolation) -> SassResult<Vec<CssMediaQuery>> {
fn visit_media_queries(
&mut self,
queries: Interpolation,
span: Span,
) -> SassResult<Vec<CssMediaQuery>> {
let resolved = self.perform_interpolation(queries, true)?;
CssMediaQuery::parse_list(&resolved, self.span_before)
CssMediaQuery::parse_list(&resolved, span)
}
fn visit_media_rule(&mut self, media_rule: AstMedia) -> SassResult<Option<Value>> {
@ -1237,7 +1241,7 @@ impl<'a> Visitor<'a> {
.into());
}
let queries1 = self.visit_media_queries(media_rule.query)?;
let queries1 = self.visit_media_queries(media_rule.query, media_rule.query_span)?;
// todo: superfluous clone?
let queries2 = self.media_queries.clone();
let merged_queries = queries2

View File

@ -387,7 +387,6 @@ pub(crate) trait BaseParser<'a> {
while let Some(tok) = self.toks().peek() {
match tok.kind {
'\\' => {
self.toks_mut().next();
buffer.push_str(&self.parse_escape(true)?);
wrote_newline = false;
}

View File

@ -981,12 +981,15 @@ pub(crate) trait StylesheetParser<'a>: BaseParser<'a> + Sized {
}
fn parse_media_rule(&mut self, start: usize) -> SassResult<AstStmt> {
let query_start = self.toks().cursor();
let query = self.parse_media_query_list()?;
let query_span = self.toks_mut().span_from(query_start);
let body = self.with_children(Self::parse_statement)?.node;
Ok(AstStmt::Media(AstMedia {
query,
query_span,
body,
span: self.toks_mut().span_from(start),
}))

View File

@ -561,6 +561,15 @@ test!(
}",
"@media (url) {\n a {\n color: red;\n }\n}\n"
);
test!(
escaped_nullbyte_in_query,
r#"@media (min-width:\0) {
a {
color: red;
}
}"#,
"@media (min-width: \\0 ) {\n a {\n color: red;\n }\n}\n"
);
error!(
media_query_has_quoted_closing_paren,
r#"@media ('a)'w) {