Skip to content

Commit c5caf83

Browse files
committed
Add error message for empty interpolations
And fixes a minor error in css error reporting
1 parent 348fde8 commit c5caf83

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

parser.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ namespace Sass {
482482
// accumulate the preceding segment if the position has advanced
483483
if (i < p) (*schema) << new (ctx.mem) String_Quoted(pstate, string(i, p));
484484
// skip to the delimiter by skipping occurences in quoted strings
485+
if (peek < sequence < optional_spaces, exactly<rbrace> > >(p+2)) { position = p+2;
486+
css_error("Invalid CSS", " after ", ": expected expression (e.g. 1px, bold), was ");
487+
}
485488
const char* j = skip_over_scopes< exactly<hash_lbrace>, exactly<rbrace> >(p + 2, end_of_selector);
486489
Expression* interpolant = Parser::from_c_str(p+2, j, ctx, pstate).parse_list();
487490
interpolant->is_interpolant(true);
@@ -1387,6 +1390,9 @@ namespace Sass {
13871390
}
13881391
// we need to skip anything inside strings
13891392
// create a new target in parser/prelexer
1393+
if (peek < sequence < optional_spaces, exactly<rbrace> > >(p+2)) { position = p+2;
1394+
css_error("Invalid CSS", " after ", ": expected expression (e.g. 1px, bold), was ");
1395+
}
13901396
const char* j = skip_over_scopes< exactly<hash_lbrace>, exactly<rbrace> >(p + 2, chunk.end); // find the closing brace
13911397
if (j) { --j;
13921398
// parse the interpolant and accumulate it
@@ -1458,6 +1464,9 @@ namespace Sass {
14581464
if (i < p) {
14591465
(*schema) << new (ctx.mem) String_Constant(pstate, string(i, p)); // accumulate the preceding segment if it's nonempty
14601466
}
1467+
if (peek < sequence < optional_spaces, exactly<rbrace> > >(p+2)) { position = p+2;
1468+
css_error("Invalid CSS", " after ", ": expected expression (e.g. 1px, bold), was ");
1469+
}
14611470
const char* j = skip_over_scopes< exactly<hash_lbrace>, exactly<rbrace> >(p+2, str.end); // find the closing brace
14621471
if (j) {
14631472
// parse the interpolant and accumulate it
@@ -1502,6 +1511,9 @@ namespace Sass {
15021511
{
15031512
String_Schema* schema = new (ctx.mem) String_Schema(pstate);
15041513
size_t num_items = 0;
1514+
if (peek<exactly<'}'>>()) {
1515+
css_error("Invalid CSS", " after ", ": expected expression (e.g. 1px, bold), was ");
1516+
}
15051517
while (position < stop) {
15061518
if (lex< interpolant >()) {
15071519
Token insides(Token(lexed.begin + 2, lexed.end - 1));
@@ -1595,6 +1607,9 @@ namespace Sass {
15951607
}
15961608
// we need to skip anything inside strings
15971609
// create a new target in parser/prelexer
1610+
if (peek < sequence < optional_spaces, exactly<rbrace> > >(p+2)) { position = p+2;
1611+
css_error("Invalid CSS", " after ", ": expected expression (e.g. 1px, bold), was ");
1612+
}
15981613
const char* j = skip_over_scopes< exactly<hash_lbrace>, exactly<rbrace> >(p+2, id.end); // find the closing brace
15991614
if (j) {
16001615
// parse the interpolant and accumulate it
@@ -2229,14 +2244,16 @@ namespace Sass {
22292244
const char* pos = peek < optional_spaces >();
22302245
bool ellipsis_left = false;
22312246
const char* pos_left(pos);
2232-
while (*pos_left && pos_left >= source) {
2247+
while (*pos_left && pos_left > source) {
22332248
if (pos - pos_left > max_len) {
22342249
ellipsis_left = true;
22352250
break;
22362251
}
2237-
if (*pos_left == '\r') break;
2238-
if (*pos_left == '\n') break;
2239-
-- pos_left;
2252+
const char* prev = pos_left - 1;
2253+
if (*prev == '\r') break;
2254+
if (*prev == '\n') break;
2255+
if (*prev == 10) break;
2256+
pos_left = prev;
22402257
}
22412258
bool ellipsis_right = false;
22422259
const char* pos_right(pos);
@@ -2247,6 +2264,7 @@ namespace Sass {
22472264
}
22482265
if (*pos_right == '\r') break;
22492266
if (*pos_right == '\n') break;
2267+
if (*pos_left == 10) break;
22502268
++ pos_right;
22512269
}
22522270
string left(pos_left, pos);

0 commit comments

Comments
 (0)