@@ -1783,11 +1783,28 @@ namespace Sass {
17831783 Expression_Obj sel = s->contents ()->perform (this );
17841784 std::string result_str (sel->to_string (ctx.c_options ));
17851785 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 ());
17871789 p.last_media_block = s->media_block ();
17881790 // a selector schema may or may not connect to parent?
17891791 bool chroot = s->connect_parent () == false ;
17901792 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+ }
17911808 flag_is_in_selector_schema.reset ();
17921809 return operator ()(sl);
17931810 }
0 commit comments