Skip to content

Commit ba0b3e0

Browse files
committed
Merge pull request #1004 from mgreter/bugfix/parent-selector-eval
Fix edge case in `Parent_Selector` evaluation
2 parents 4b689ac + 8439c1c commit ba0b3e0

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

contextualize_eval.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ namespace Sass {
1414
Contextualize_Eval::~Contextualize_Eval() { }
1515

1616
Selector* Contextualize_Eval::fallback_impl(AST_Node* n)
17-
{ return Contextualize::fallback_impl(n); }
17+
{
18+
return Contextualize::fallback_impl(n);
19+
}
1820

1921
Contextualize_Eval* Contextualize_Eval::with(Selector* s, Env* e, Backtrace* bt, Selector* p, Selector* ex)
2022
{
@@ -53,14 +55,17 @@ namespace Sass {
5355
}
5456

5557
Selector* Contextualize_Eval::operator()(Pseudo_Selector* s)
56-
{ return Contextualize::operator ()(s); }
58+
{
59+
return Contextualize::operator ()(s);
60+
}
5761

5862
Selector* Contextualize_Eval::operator()(Attribute_Selector* s)
5963
{
6064
// the value might be interpolated; evaluate it
6165
String* v = s->value();
6266
if (v && eval) {
63-
v = static_cast<String*>(v->perform(eval->with(env, backtrace)));
67+
Eval* eval_with = eval->with(env, backtrace);
68+
v = static_cast<String*>(v->perform(eval_with));
6469
}
6570
To_String toString;
6671
Attribute_Selector* ss = new (ctx.mem) Attribute_Selector(*s);

error_handling.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ namespace Sass {
88
: type(type), pstate(pstate), message(message)
99
{ }
1010

11-
void error(string msg, ParserState pstate)
12-
{ throw Sass_Error(Sass_Error::syntax, pstate, msg); }
11+
void error(string msg, ParserState pstate) throw(Sass_Error)
12+
{
13+
throw Sass_Error(Sass_Error::syntax, pstate, msg);
14+
}
1315

14-
void error(string msg, ParserState pstate, Backtrace* bt)
16+
void error(string msg, ParserState pstate, Backtrace* bt) throw(Sass_Error)
1517
{
1618

1719
Backtrace top(bt, pstate, "");

error_handling.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ namespace Sass {
2121

2222
};
2323

24-
void error(string msg, ParserState pstate);
25-
void error(string msg, ParserState pstate, Backtrace* bt);
24+
void error(string msg, ParserState pstate) throw(Sass_Error);
25+
void error(string msg, ParserState pstate, Backtrace* bt) throw(Sass_Error);
2626

2727
}
2828

eval.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,8 +972,10 @@ namespace Sass {
972972
Expression* Eval::operator()(Parent_Selector* p)
973973
{
974974
Selector* s = p->perform(contextualize);
975-
Expression* e = static_cast<Selector_List*>(s)->perform(listize);
976-
return e;
975+
// access to parent selector may return 0
976+
Selector_List* l = static_cast<Selector_List*>(s);
977+
if (!s) { l = new (ctx.mem) Selector_List(p->pstate()); }
978+
return l->perform(listize);
977979
}
978980

979981
inline Expression* Eval::fallback_impl(AST_Node* n)

0 commit comments

Comments
 (0)