test for crazy interpolation inside @if

This commit is contained in:
Connor Skees 2020-07-08 09:08:25 -04:00
parent 0c0c154b66
commit b42ae61435
3 changed files with 32 additions and 6 deletions

View File

@ -545,9 +545,8 @@ impl<'a> Parser<'a> {
self.throw_away_until_closing_curly_brace()?;
}
self.whitespace_or_comment();
loop {
self.whitespace_or_comment();
if let Some(Token { kind: '@', pos }) = self.toks.peek().cloned() {
self.toks.peek_forward(1);
let ident = peek_ident_no_interpolation(self.toks, false, pos)?;

View File

@ -27,10 +27,14 @@ impl<'a> Parser<'a> {
return Err((format!("Expected {}.", q), tok.pos).into());
}
}
'#' => {
'#' => match self.toks.peek() {
Some(Token { kind: '{', .. }) => {
self.toks.next();
self.throw_away_until_closing_curly_brace()?;
}
Some(..) => {}
None => return Err(("expected \"{\".", self.span_before).into()),
},
_ => {}
}
}

View File

@ -140,6 +140,29 @@ test!(
"@mixin foo {\n color: red;\n}\n\n@if true {\n a {\n @include foo;\n }\n}\n",
"a {\n color: red;\n}\n"
);
test!(
crazy_interpolation,
"a {
@if true {
a: #{\"#{\"\\\\}}}{{{\"}#\"};
}
@if false {
a: #{\"#{\"\\\\}}}{{{\"}#\"};
} @else if true {
b: #{\"#{\"\\\\}}}{{{\"}#\"};
}
@if false {
a: #{\"#{\"\\\\}}}{{{\"}#\"};
} @else if false {
b: #{\"#{\"\\\\}}}{{{\"}#\"};
} @else {
c: #{\"#{\"\\\\}}}{{{\"}#\"};
}
}",
"a {\n a: \\}}}{{{#;\n b: \\}}}{{{#;\n c: \\}}}{{{#;\n}\n"
);
error!(
nothing_after_escape,
"@if \\", "Error: Expected expression."