Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on incomplete @supports clause in parser #2860

Merged
merged 1 commit into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2415,10 +2415,7 @@ namespace Sass {
// these are very similar to media blocks
Supports_Block_Obj Parser::parse_supports_directive()
{
Supports_Condition_Obj cond = parse_supports_condition();
if (!cond) {
css_error("Invalid CSS", " after ", ": expected @supports condition (e.g. (display: flexbox)), was ", false);
}
Supports_Condition_Obj cond = parse_supports_condition(/*top_level=*/true);
// create the ast node object for the support queries
Supports_Block_Obj query = SASS_MEMORY_NEW(Supports_Block, pstate, cond);
// additional block is mandatory
Expand All @@ -2430,26 +2427,26 @@ namespace Sass {

// parse one query operation
// may encounter nested queries
Supports_Condition_Obj Parser::parse_supports_condition()
Supports_Condition_Obj Parser::parse_supports_condition(bool top_level)
{
lex < css_whitespace >();
Supports_Condition_Obj cond;
if ((cond = parse_supports_negation())) return cond;
if ((cond = parse_supports_operator())) return cond;
if ((cond = parse_supports_operator(top_level))) return cond;
if ((cond = parse_supports_interpolation())) return cond;
return cond;
}

Supports_Condition_Obj Parser::parse_supports_negation()
{
if (!lex < kwd_not >()) return {};
Supports_Condition_Obj cond = parse_supports_condition_in_parens();
Supports_Condition_Obj cond = parse_supports_condition_in_parens(/*parens_required=*/true);
return SASS_MEMORY_NEW(Supports_Negation, pstate, cond);
}

Supports_Condition_Obj Parser::parse_supports_operator()
Supports_Condition_Obj Parser::parse_supports_operator(bool top_level)
{
Supports_Condition_Obj cond = parse_supports_condition_in_parens();
Supports_Condition_Obj cond = parse_supports_condition_in_parens(/*parens_required=*/top_level);
if (cond.isNull()) return {};

while (true) {
Expand All @@ -2458,7 +2455,7 @@ namespace Sass {
else if(!lex < kwd_or >()) { break; }

lex < css_whitespace >();
Supports_Condition_Obj right = parse_supports_condition_in_parens();
Supports_Condition_Obj right = parse_supports_condition_in_parens(/*parens_required=*/true);

// Supports_Condition* cc = SASS_MEMORY_NEW(Supports_Condition, *static_cast<Supports_Condition*>(cond));
cond = SASS_MEMORY_NEW(Supports_Operator, pstate, cond, right, op);
Expand Down Expand Up @@ -2496,21 +2493,24 @@ namespace Sass {
return cond;
}

Supports_Condition_Obj Parser::parse_supports_condition_in_parens()
Supports_Condition_Obj Parser::parse_supports_condition_in_parens(bool parens_required)
{
Supports_Condition_Obj interp = parse_supports_interpolation();
if (interp != 0) return interp;

if (!lex < exactly <'('> >()) return {};
if (!lex < exactly <'('> >()) {
if (parens_required) {
css_error("Invalid CSS", " after ", ": expected @supports condition (e.g. (display: flexbox)), was ", /*trim=*/false);
} else {
return {};
}
}
lex < css_whitespace >();

Supports_Condition_Obj cond = parse_supports_condition();
if (cond != 0) {
if (!lex < exactly <')'> >()) error("unclosed parenthesis in @supports declaration");
} else {
cond = parse_supports_declaration();
if (!lex < exactly <')'> >()) error("unclosed parenthesis in @supports declaration");
}
Supports_Condition_Obj cond = parse_supports_condition(/*top_level=*/false);
if (cond.isNull()) cond = parse_supports_declaration();
if (!lex < exactly <')'> >()) error("unclosed parenthesis in @supports declaration");

lex < css_whitespace >();
return cond;
}
Expand Down
6 changes: 3 additions & 3 deletions src/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,12 @@ namespace Sass {
Media_Query_Obj parse_media_query();
Media_Query_Expression_Obj parse_media_expression();
Supports_Block_Obj parse_supports_directive();
Supports_Condition_Obj parse_supports_condition();
Supports_Condition_Obj parse_supports_condition(bool top_level);
Supports_Condition_Obj parse_supports_negation();
Supports_Condition_Obj parse_supports_operator();
Supports_Condition_Obj parse_supports_operator(bool top_level);
Supports_Condition_Obj parse_supports_interpolation();
Supports_Condition_Obj parse_supports_declaration();
Supports_Condition_Obj parse_supports_condition_in_parens();
Supports_Condition_Obj parse_supports_condition_in_parens(bool parens_required);
At_Root_Block_Obj parse_at_root_block();
At_Root_Query_Obj parse_at_root_query();
String_Schema_Obj parse_almost_any_value();
Expand Down