@@ -1783,11 +1783,28 @@ namespace Sass {
1783
1783
Expression_Obj sel = s->contents ()->perform (this );
1784
1784
std::string result_str (sel->to_string (ctx.c_options ));
1785
1785
result_str = unquote (Util::rtrim (result_str));
1786
- Parser p = Parser::from_c_str (result_str.c_str (), ctx, s->pstate ());
1786
+ char * temp_cstr = sass_copy_c_string (result_str.c_str ());
1787
+ ctx.strings .push_back (temp_cstr); // attach to context
1788
+ Parser p = Parser::from_c_str (temp_cstr, ctx, s->pstate ());
1787
1789
p.last_media_block = s->media_block ();
1788
1790
// a selector schema may or may not connect to parent?
1789
1791
bool chroot = s->connect_parent () == false ;
1790
1792
Selector_List_Obj sl = p.parse_selector_list (chroot);
1793
+ auto vec_str_rend = ctx.strings .rend ();
1794
+ auto vec_str_rbegin = ctx.strings .rbegin ();
1795
+ // remove the first item searching from the back
1796
+ // we cannot assume our item is still the last one
1797
+ // order is not important, so we can optimize this
1798
+ auto it = std::find (vec_str_rbegin, vec_str_rend, temp_cstr);
1799
+ // undefined behavior if not found!
1800
+ if (it != vec_str_rend) {
1801
+ // overwrite with last item
1802
+ *it = ctx.strings .back ();
1803
+ // remove last one from vector
1804
+ ctx.strings .pop_back ();
1805
+ // free temporary copy
1806
+ free (temp_cstr);
1807
+ }
1791
1808
flag_is_in_selector_schema.reset ();
1792
1809
return operator ()(sl);
1793
1810
}
0 commit comments