improve error message for selector-parse
and deny open curly brace
This commit is contained in:
parent
0c7e2017d5
commit
5133d580de
@ -55,7 +55,8 @@ pub(crate) fn selector_parse(mut args: CallArgs, parser: &mut Parser<'_>) -> Sas
|
||||
args.max_args(1)?;
|
||||
Ok(args
|
||||
.get_err(0, "selector")?
|
||||
.to_selector(parser, "selector", false)?
|
||||
.to_selector(parser, "selector", false)
|
||||
.map_err(|_| ("$selector: expected selector.", args.span()))?
|
||||
.into_value())
|
||||
}
|
||||
|
||||
|
@ -398,9 +398,9 @@ impl<'a> Parser<'a> {
|
||||
let mut optional = false;
|
||||
|
||||
// we resolve interpolation and strip comments
|
||||
while let Some(tok) = self.toks.next() {
|
||||
span = span.merge(tok.pos());
|
||||
match tok.kind {
|
||||
while let Some(Token { kind, pos }) = self.toks.next() {
|
||||
span = span.merge(pos);
|
||||
match kind {
|
||||
'#' => {
|
||||
if let Some(Token { kind: '{', .. }) = self.toks.peek().cloned() {
|
||||
self.toks.next();
|
||||
@ -411,15 +411,19 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
'/' => {
|
||||
if self.toks.peek().is_none() {
|
||||
return Err(("Expected selector.", tok.pos()).into());
|
||||
return Err(("Expected selector.", pos).into());
|
||||
}
|
||||
self.parse_comment()?;
|
||||
string.push(' ');
|
||||
}
|
||||
'{' => {
|
||||
if from_fn {
|
||||
return Err(("Expected selector.", pos).into());
|
||||
} else {
|
||||
found_curly = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
'\\' => {
|
||||
string.push('\\');
|
||||
if let Some(Token { kind, .. }) = self.toks.next() {
|
||||
@ -431,7 +435,7 @@ impl<'a> Parser<'a> {
|
||||
self.expect_identifier("optional")?;
|
||||
optional = true;
|
||||
} else {
|
||||
return Err(("expected \"{\".", tok.pos).into());
|
||||
return Err(("expected \"{\".", pos).into());
|
||||
}
|
||||
}
|
||||
c => string.push(c),
|
||||
|
@ -98,3 +98,11 @@ test!(
|
||||
"a {\n color: selector-parse(\"b c, d e, f g\");\n}\n",
|
||||
"a {\n color: b c, d e, f g;\n}\n"
|
||||
);
|
||||
error!(
|
||||
invalid_selector,
|
||||
"a {\n color: selector-parse(\"!!!!!!!!\");\n}\n", "Error: $selector: expected selector."
|
||||
);
|
||||
error!(
|
||||
selector_contains_curly_brace,
|
||||
"a {\n color: selector-parse(\"a {\");\n}\n", "Error: $selector: expected selector."
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user