Skip to content

Commit 368ece6

Browse files
committed
Merge pull request #1180 from mgreter/bugfix/issue_1093
Add error message for empty interpolations
2 parents b4cd48f + c5caf83 commit 368ece6

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);
@@ -1399,6 +1402,9 @@ namespace Sass {
13991402
}
14001403
// we need to skip anything inside strings
14011404
// create a new target in parser/prelexer
1405+
if (peek < sequence < optional_spaces, exactly<rbrace> > >(p+2)) { position = p+2;
1406+
css_error("Invalid CSS", " after ", ": expected expression (e.g. 1px, bold), was ");
1407+
}
14021408
const char* j = skip_over_scopes< exactly<hash_lbrace>, exactly<rbrace> >(p + 2, chunk.end); // find the closing brace
14031409
if (j) { --j;
14041410
// parse the interpolant and accumulate it
@@ -1470,6 +1476,9 @@ namespace Sass {
14701476
if (i < p) {
14711477
(*schema) << new (ctx.mem) String_Constant(pstate, string(i, p)); // accumulate the preceding segment if it's nonempty
14721478
}
1479+
if (peek < sequence < optional_spaces, exactly<rbrace> > >(p+2)) { position = p+2;
1480+
css_error("Invalid CSS", " after ", ": expected expression (e.g. 1px, bold), was ");
1481+
}
14731482
const char* j = skip_over_scopes< exactly<hash_lbrace>, exactly<rbrace> >(p+2, str.end); // find the closing brace
14741483
if (j) {
14751484
// parse the interpolant and accumulate it
@@ -1514,6 +1523,9 @@ namespace Sass {
15141523
{
15151524
String_Schema* schema = new (ctx.mem) String_Schema(pstate);
15161525
size_t num_items = 0;
1526+
if (peek<exactly<'}'>>()) {
1527+
css_error("Invalid CSS", " after ", ": expected expression (e.g. 1px, bold), was ");
1528+
}
15171529
while (position < stop) {
15181530
if (lex< spaces >() && num_items) {
15191531
(*schema) << new (ctx.mem) String_Constant(pstate, " ");
@@ -1610,6 +1622,9 @@ namespace Sass {
16101622
}
16111623
// we need to skip anything inside strings
16121624
// create a new target in parser/prelexer
1625+
if (peek < sequence < optional_spaces, exactly<rbrace> > >(p+2)) { position = p+2;
1626+
css_error("Invalid CSS", " after ", ": expected expression (e.g. 1px, bold), was ");
1627+
}
16131628
const char* j = skip_over_scopes< exactly<hash_lbrace>, exactly<rbrace> >(p+2, id.end); // find the closing brace
16141629
if (j) {
16151630
// parse the interpolant and accumulate it
@@ -2295,14 +2310,16 @@ namespace Sass {
22952310
const char* pos = peek < optional_spaces >();
22962311
bool ellipsis_left = false;
22972312
const char* pos_left(pos);
2298-
while (*pos_left && pos_left >= source) {
2313+
while (*pos_left && pos_left > source) {
22992314
if (pos - pos_left > max_len) {
23002315
ellipsis_left = true;
23012316
break;
23022317
}
2303-
if (*pos_left == '\r') break;
2304-
if (*pos_left == '\n') break;
2305-
-- pos_left;
2318+
const char* prev = pos_left - 1;
2319+
if (*prev == '\r') break;
2320+
if (*prev == '\n') break;
2321+
if (*prev == 10) break;
2322+
pos_left = prev;
23062323
}
23072324
bool ellipsis_right = false;
23082325
const char* pos_right(pos);
@@ -2313,6 +2330,7 @@ namespace Sass {
23132330
}
23142331
if (*pos_right == '\r') break;
23152332
if (*pos_right == '\n') break;
2333+
if (*pos_left == 10) break;
23162334
++ pos_right;
23172335
}
23182336
string left(pos_left, pos);

0 commit comments

Comments
 (0)