Skip to content

Commit ee45dae

Browse files
committed
Hotfix for interpolation adding additional escapes
1 parent e1085b6 commit ee45dae

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/eval.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ namespace Sass {
861861
}
862862
}
863863

864-
std::string Eval::interpolation(Expression* s) {
864+
std::string Eval::interpolation(Expression* s, bool into_quotes) {
865865
Env* env = environment();
866866
if (String_Quoted* str_quoted = dynamic_cast<String_Quoted*>(s)) {
867867
if (str_quoted->quote_mark()) {
@@ -874,6 +874,7 @@ namespace Sass {
874874
return evacuate_escapes(str_quoted->value());
875875
}
876876
} else if (String_Constant* str_constant = dynamic_cast<String_Constant*>(s)) {
877+
if (into_quotes && !str_constant->is_interpolant()) return str_constant->value();
877878
return evacuate_escapes(str_constant->value());
878879
} else if (dynamic_cast<Parent_Selector*>(s)) {
879880
To_String to_string(&ctx);
@@ -936,7 +937,17 @@ namespace Sass {
936937
Expression* Eval::operator()(String_Schema* s)
937938
{
938939
std::string acc;
939-
for (size_t i = 0, L = s->length(); i < L; ++i) {
940+
bool into_quotes = false;
941+
size_t L = s->length();
942+
if (L > 1) {
943+
if (String_Constant* l = dynamic_cast<String_Constant*>((*s)[0])) {
944+
if (String_Constant* r = dynamic_cast<String_Constant*>((*s)[L - 1])) {
945+
if (l->value()[0] == '"' && r->value()[r->value().size() - 1] == '"') into_quotes = true;
946+
if (l->value()[0] == '\'' && r->value()[r->value().size() - 1] == '\'') into_quotes = true;
947+
}
948+
}
949+
}
950+
for (size_t i = 0; i < L; ++i) {
940951
// really a very special fix, but this is the logic I got from
941952
// analyzing the ruby sass behavior and it actually seems to work
942953
// https://github.com/sass/libsass/issues/1333
@@ -946,13 +957,13 @@ namespace Sass {
946957
if (sq->is_delayed() && ! s->has_interpolants()) {
947958
acc += string_escape(quote(sq->value(), sq->quote_mark()));
948959
} else {
949-
acc += interpolation((*s)[i]);
960+
acc += interpolation((*s)[i], into_quotes);
950961
}
951962
} else if (ex) {
952-
acc += interpolation((*s)[i]);
963+
acc += interpolation((*s)[i], into_quotes);
953964
}
954965
} else if ((*s)[i]) {
955-
acc += interpolation((*s)[i]);
966+
acc += interpolation((*s)[i], into_quotes);
956967
}
957968
}
958969
String_Quoted* str = SASS_MEMORY_NEW(ctx.mem, String_Quoted, s->pstate(), acc);

src/eval.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ namespace Sass {
9696
static Value* op_strings(Memory_Manager<AST_Node>&, enum Sass_OP, Value&, Value&, bool compressed = false, int precision = 5);
9797

9898
private:
99-
std::string interpolation(Expression* s);
99+
std::string interpolation(Expression* s, bool into_quotes = false);
100100

101101
};
102102

0 commit comments

Comments
 (0)