Skip to content

Commit 213339a

Browse files
committed
Merge pull request #1955 from xzyfer/fix/issue-1644
Fix error not being thrown when & is used without a parent selector
2 parents f5b02c9 + 32c921a commit 213339a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/expand.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ namespace Sass {
117117
Selector_List* sel = dynamic_cast<Selector_List*>(ex);
118118
if (sel == 0) throw std::runtime_error("Expanded null selector");
119119

120+
if (sel->length() == 0 || sel->has_parent_ref()) {
121+
bool has_parent_selector = false;
122+
for (size_t i = 0, L = selector_stack.size(); i < L && !has_parent_selector; i++) {
123+
Selector_List* ll = selector_stack.at(i);
124+
has_parent_selector = ll != 0 && ll->length() > 0;
125+
}
126+
if (!has_parent_selector) {
127+
error("Base-level rules cannot contain the parent-selector-referencing character '&'.", sel->pstate(), backtrace());
128+
}
129+
}
130+
120131
selector_stack.push_back(sel);
121132
Env* env = 0;
122133
if (block_stack.back()->is_root()) {

0 commit comments

Comments
 (0)