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)] #[derive(Debug, Clone)]
pub(crate) struct AstMedia { pub(crate) struct AstMedia {
pub query: Interpolation, pub query: Interpolation,
pub query_span: Span,
pub body: Vec<AstStmt>, pub body: Vec<AstStmt>,
pub span: Span, pub span: Span,
} }

View File

@ -1222,10 +1222,14 @@ impl<'a> Visitor<'a> {
Some(queries) 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)?; 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>> { fn visit_media_rule(&mut self, media_rule: AstMedia) -> SassResult<Option<Value>> {
@ -1237,7 +1241,7 @@ impl<'a> Visitor<'a> {
.into()); .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? // todo: superfluous clone?
let queries2 = self.media_queries.clone(); let queries2 = self.media_queries.clone();
let merged_queries = queries2 let merged_queries = queries2

View File

@ -387,7 +387,6 @@ pub(crate) trait BaseParser<'a> {
while let Some(tok) = self.toks().peek() { while let Some(tok) = self.toks().peek() {
match tok.kind { match tok.kind {
'\\' => { '\\' => {
self.toks_mut().next();
buffer.push_str(&self.parse_escape(true)?); buffer.push_str(&self.parse_escape(true)?);
wrote_newline = false; 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> { 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 = self.parse_media_query_list()?;
let query_span = self.toks_mut().span_from(query_start);
let body = self.with_children(Self::parse_statement)?.node; let body = self.with_children(Self::parse_statement)?.node;
Ok(AstStmt::Media(AstMedia { Ok(AstStmt::Media(AstMedia {
query, query,
query_span,
body, body,
span: self.toks_mut().span_from(start), span: self.toks_mut().span_from(start),
})) }))

View File

@ -561,6 +561,15 @@ test!(
}", }",
"@media (url) {\n a {\n color: red;\n }\n}\n" "@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!( error!(
media_query_has_quoted_closing_paren, media_query_has_quoted_closing_paren,
r#"@media ('a)'w) { r#"@media ('a)'w) {