Skip to content

Commit 4fe91c6

Browse files
committed
Implement keep_utf8_sequences for unquote function
1 parent 7d2c89a commit 4fe91c6

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

src/ast.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,10 +1424,10 @@ namespace Sass {
14241424
////////////////////////////////////////////////////////
14251425
class String_Quoted : public String_Constant {
14261426
public:
1427-
String_Quoted(ParserState pstate, std::string val, char q = 0)
1427+
String_Quoted(ParserState pstate, std::string val, char q = 0, bool keep_utf8_escapes = false)
14281428
: String_Constant(pstate, val)
14291429
{
1430-
value_ = unquote(value_, &quote_mark_);
1430+
value_ = unquote(value_, &quote_mark_, keep_utf8_escapes);
14311431
if (q && quote_mark_) quote_mark_ = q;
14321432
}
14331433
virtual bool operator==(const Expression& rhs) const;

src/eval.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,12 +1327,17 @@ namespace Sass {
13271327
if (ltype == Expression::NULL_VAL) error("invalid null operation: \"null plus "+quote(unquote(rstr), '"')+"\".", lhs.pstate());
13281328
if (rtype == Expression::NULL_VAL) error("invalid null operation: \""+quote(unquote(lstr), '"')+" plus null\".", rhs.pstate());
13291329

1330-
String_Constant* str = (ltype == Expression::STRING || sep == "") &&
1331-
(sep != "/" || !rqstr || !rqstr->quote_mark())
1332-
? SASS_MEMORY_NEW(mem, String_Quoted, lhs.pstate(), (lstr) + sep + (rstr))
1333-
: SASS_MEMORY_NEW(mem, String_Constant, lhs.pstate(), (lstr) + sep + quote(rstr));
1334-
str->quote_mark(0);
1335-
return str;
1330+
if ( (ltype == Expression::STRING || sep == "") &&
1331+
(sep != "/" || !rqstr || !rqstr->quote_mark())
1332+
) {
1333+
char quote_mark = 0;
1334+
std::string unq(unquote(lstr + sep + rstr, &quote_mark, true));
1335+
if (quote_mark && quote_mark != '*') {
1336+
return SASS_MEMORY_NEW(mem, String_Constant, lhs.pstate(), quote_mark + unq + quote_mark);
1337+
}
1338+
return SASS_MEMORY_NEW(mem, String_Quoted, lhs.pstate(), lstr + sep + rstr);
1339+
}
1340+
return SASS_MEMORY_NEW(mem, String_Constant, lhs.pstate(), (lstr) + sep + quote(rstr));
13361341
}
13371342

13381343
Expression* cval_to_astnode(Memory_Manager<AST_Node>& mem, union Sass_Value* v, Context& ctx, Backtrace* backtrace, ParserState pstate)

src/util.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ namespace Sass {
317317
return quote_mark;
318318
}
319319

320-
std::string unquote(const std::string& s, char* qd)
320+
std::string unquote(const std::string& s, char* qd, bool keep_utf8_sequences)
321321
{
322322

323323
// not enough room for quotes
@@ -357,7 +357,9 @@ namespace Sass {
357357
while (i + len < L && s[i + len] && isxdigit(s[i + len])) ++ len;
358358

359359
// hex string?
360-
if (len > 1) {
360+
if (keep_utf8_sequences) {
361+
unq.push_back(s[i]);
362+
} else if (len > 1) {
361363

362364
// convert the extracted hex string to code point value
363365
// ToDo: Maybe we could do this without creating a substring

src/util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Sass {
2323
std::string normalize_wspace(const std::string& str);
2424

2525
std::string quote(const std::string&, char q = 0, bool keep_linefeed_whitespace = false);
26-
std::string unquote(const std::string&, char* q = 0);
26+
std::string unquote(const std::string&, char* q = 0, bool keep_utf8_sequences = false);
2727
char detect_best_quotemark(const char* s, char qm = '"');
2828

2929
bool is_hex_doublet(double n);

0 commit comments

Comments
 (0)