Skip to content

Commit daf9163

Browse files
committed
Merge pull request #1136 from xzyfer/fix/property-strings
Misc fixes for string handling regressions
2 parents f3dd7e1 + 85649d3 commit daf9163

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

debugger.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
489489
cerr << " [" << prettyprint(expression->value()) << "]" <<
490490
(expression->is_delayed() ? " {delayed}" : "") <<
491491
(expression->sass_fix_1291() ? " {sass_fix_1291}" : "") <<
492+
(expression->quote_mark() != 0 ? " {qm:" + string(1, expression->quote_mark()) + "}" : "") <<
492493
" <" << prettyprint(expression->pstate().token.ws_before()) << ">" << endl;
493494
} else if (dynamic_cast<String_Schema*>(node)) {
494495
String_Schema* expression = dynamic_cast<String_Schema*>(node);

eval.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,11 @@ namespace Sass {
700700
if (auto str = dynamic_cast<String_Quoted*>(value)) {
701701
value = new (ctx.mem) String_Quoted(*str);
702702
} else if (auto str = dynamic_cast<String_Constant*>(value)) {
703-
value = new (ctx.mem) String_Constant(*str);
703+
if (str->quote_mark()) {
704+
value = new (ctx.mem) String_Quoted(str->pstate(), str->perform(&to_string));
705+
} else {
706+
value = new (ctx.mem) String_Constant(str->pstate(), unquote(str->value()));
707+
}
704708
}
705709
}
706710
else if (value->concrete_type() == Expression::LIST) {
@@ -812,12 +816,18 @@ namespace Sass {
812816
string Eval::interpolation(Expression* s) {
813817
if (String_Quoted* str_quoted = dynamic_cast<String_Quoted*>(s)) {
814818
if (str_quoted->quote_mark()) {
815-
return string_escape(str_quoted->value());
819+
if (str_quoted->quote_mark() == '*' || str_quoted->is_delayed()) {
820+
return interpolation(new (ctx.mem) String_Constant(*str_quoted));
821+
} else {
822+
return string_escape(quote(str_quoted->value(), str_quoted->quote_mark()));
823+
}
816824
} else {
817825
return evacuate_escapes(str_quoted->value());
818826
}
819827
} else if (String_Constant* str_constant = dynamic_cast<String_Constant*>(s)) {
820-
return evacuate_escapes(str_constant->value());
828+
string str = str_constant->value();
829+
if (!str_constant->quote_mark()) str = unquote(str);
830+
return evacuate_escapes(str);
821831
} else if (String_Schema* str_schema = dynamic_cast<String_Schema*>(s)) {
822832
string res = "";
823833
for(auto i : str_schema->elements())

functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ namespace Sass {
771771
return result;
772772
}
773773
To_String to_string(&ctx);
774-
return new (ctx.mem) String_Constant(pstate, string(arg->perform(&to_string)));
774+
return new (ctx.mem) String_Constant(pstate, unquote(string(arg->perform(&to_string))));
775775
}
776776

777777
Signature quote_sig = "quote($string)";

parser.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,7 @@ namespace Sass {
14151415
Token str(lexed);
14161416
const char* i = str.begin;
14171417
// see if there any interpolants
1418+
const char* q;
14181419
const char* p = find_first_in_interval< exactly<hash_lbrace> >(str.begin, str.end);
14191420
if (!p) {
14201421
String_Constant* str_node = new (ctx.mem) String_Constant(pstate, normalize_wspace(string(str.begin, str.end)));
@@ -1424,8 +1425,16 @@ namespace Sass {
14241425

14251426
String_Schema* schema = new (ctx.mem) String_Schema(pstate);
14261427
while (i < str.end) {
1428+
q = find_first_in_interval< alternatives< exactly<'"'>, exactly<'\''> > >(i, str.end);
14271429
p = find_first_in_interval< exactly<hash_lbrace> >(i, str.end);
1428-
if (p) {
1430+
if (q && (!p || p > q)) {
1431+
if (i < q) {
1432+
(*schema) << new (ctx.mem) String_Constant(pstate, string(i, q)); // accumulate the preceding segment if it's nonempty
1433+
}
1434+
(*schema) << new (ctx.mem) String_Constant(pstate, string(q, q+1)); // capture the quote mark separately
1435+
i = q+1;
1436+
}
1437+
else if (p) {
14291438
if (i < p) {
14301439
(*schema) << new (ctx.mem) String_Constant(pstate, string(i, p)); // accumulate the preceding segment if it's nonempty
14311440
}
@@ -1499,7 +1508,7 @@ namespace Sass {
14991508
(*schema) << new (ctx.mem) Textual(pstate, Textual::HEX, unquote(lexed));
15001509
}
15011510
else if (lex< quoted_string >()) {
1502-
(*schema) << new (ctx.mem) String_Constant(pstate, lexed);
1511+
(*schema) << new (ctx.mem) String_Quoted(pstate, lexed);
15031512
}
15041513
else if (lex< variable >()) {
15051514
(*schema) << new (ctx.mem) Variable(pstate, Util::normalize_underscores(lexed));

util.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,12 @@ namespace Sass {
330330
}
331331
// check for unexpected delimiter
332332
// be strict and throw error back
333-
else if (!skipped && q == s[i]) {
334-
// don't be that strict
335-
return s;
336-
// this basically always means an internal error and not users fault
337-
error("Unescaped delimiter in string to unquote found. [" + s + "]", ParserState("[UNQUOTE]"));
338-
}
333+
// else if (!skipped && q == s[i]) {
334+
// // don't be that strict
335+
// return s;
336+
// // this basically always means an internal error and not users fault
337+
// error("Unescaped delimiter in string to unquote found. [" + s + "]", ParserState("[UNQUOTE]"));
338+
// }
339339
else {
340340
skipped = false;
341341
unq.push_back(s[i]);

0 commit comments

Comments
 (0)