From 32c921a809eea90bd5ab55df088ee368913eba31 Mon Sep 17 00:00:00 2001 From: xzyfer Date: Fri, 18 Mar 2016 01:28:20 +1100 Subject: [PATCH] Fix error not being thrown when & is used without a parent selector Fixes #1644 Spec sass/sass-spec#742 --- src/expand.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/expand.cpp b/src/expand.cpp index 494807016e..8bf3f92950 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -117,6 +117,17 @@ namespace Sass { Selector_List* sel = dynamic_cast(ex); if (sel == 0) throw std::runtime_error("Expanded null selector"); + if (sel->length() == 0 || sel->has_parent_ref()) { + bool has_parent_selector = false; + for (size_t i = 0, L = selector_stack.size(); i < L && !has_parent_selector; i++) { + Selector_List* ll = selector_stack.at(i); + has_parent_selector = ll != 0 && ll->length() > 0; + } + if (!has_parent_selector) { + error("Base-level rules cannot contain the parent-selector-referencing character '&'.", sel->pstate(), backtrace()); + } + } + selector_stack.push_back(sel); Env* env = 0; if (block_stack.back()->is_root()) {