Skip to content

Commit 9b8545b

Browse files
committed
Improve url parsing (support line-feeds in strings)
Fixes #1096
1 parent 8ca8816 commit 9b8545b

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

inspect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ namespace Sass {
641641
void Inspect::operator()(String_Quoted* s)
642642
{
643643
if (s->quote_mark()) {
644-
append_token(quote(s->value(), s->quote_mark()), s);
644+
append_token(quote(s->value(), s->quote_mark(), true), s);
645645
} else {
646646
append_token(s->value(), s);
647647
}

parser.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,18 @@ namespace Sass {
269269
else if (lex< uri_prefix >()) {
270270
Arguments* args = new (ctx.mem) Arguments(pstate);
271271
Function_Call* result = new (ctx.mem) Function_Call(pstate, "url", args);
272-
if (lex < uri_value >()) { // chunk seems to work too!
272+
if (lex< quoted_string >()) {
273+
Expression* the_url = parse_string();
274+
*args << new (ctx.mem) Argument(the_url->pstate(), the_url);
275+
}
276+
else if (lex < uri_value >(position)) { // chunk seems to work too!
273277
String* the_url = parse_interpolated_chunk(lexed);
274278
*args << new (ctx.mem) Argument(the_url->pstate(), the_url);
275279
}
280+
else if (peek < skip_over_scopes < exactly < '(' >, exactly < ')' > > >(position)) {
281+
Expression* the_url = parse_list(); // parse_interpolated_chunk(lexed);
282+
*args << new (ctx.mem) Argument(the_url->pstate(), the_url);
283+
}
276284
else {
277285
error("malformed URL", pstate);
278286
}

prelexer.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,12 @@ namespace Sass {
148148
exactly <'\''>,
149149
zero_plus <
150150
alternatives <
151-
// skip all escaped chars first
151+
// skip escapes
152+
sequence <
153+
exactly < '\\' >,
154+
exactly < '\r' >,
155+
exactly < '\n' >
156+
>,
152157
escape_seq,
153158
// skip interpolants
154159
interpolant,
@@ -167,7 +172,12 @@ namespace Sass {
167172
exactly <'"'>,
168173
zero_plus <
169174
alternatives <
170-
// skip all escaped chars first
175+
// skip escapes
176+
sequence <
177+
exactly < '\\' >,
178+
exactly < '\r' >,
179+
exactly < '\n' >
180+
>,
171181
escape_seq,
172182
// skip interpolants
173183
interpolant,

util.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ namespace Sass {
395395

396396
}
397397

398-
string quote(const string& s, char q)
398+
string quote(const string& s, char q, bool keep_linefeed_whitespace)
399399
{
400400

401401
// autodetect with fallback to given quote
@@ -424,6 +424,10 @@ namespace Sass {
424424
if (cp == 10) {
425425
quoted.push_back('\\');
426426
quoted.push_back('a');
427+
// we hope we can remove this flag once we figure out
428+
// why ruby sass has these different output behaviors
429+
if (keep_linefeed_whitespace)
430+
quoted.push_back(' ');
427431
} else if (cp < 127) {
428432
quoted.push_back((char) cp);
429433
} else {

util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Sass {
2121
string comment_to_string(const string& text);
2222
string normalize_wspace(const string& str);
2323

24-
string quote(const string&, char q = 0);
24+
string quote(const string&, char q = 0, bool keep_linefeed_whitespace = false);
2525
string unquote(const string&, char* q = 0);
2626
char detect_best_quotemark(const char* s, char qm = '"');
2727

0 commit comments

Comments
 (0)