Skip to content

Commit 8ececd5

Browse files
committed
Merge pull request #1575 from xzyfer/fix/issue-1093
Fix error not being thrown for empty interpolants
2 parents c39175e + 89bf73d commit 8ececd5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/parser.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,10 @@ namespace Sass {
519519

520520
Argument* Parser::parse_argument(bool has_url)
521521
{
522+
if (peek_css< sequence < exactly< hash_lbrace >, exactly< rbrace > > >()) {
523+
position += 2;
524+
css_error("Invalid CSS", " after ", ": expected expression (e.g. 1px, bold), was ");
525+
}
522526

523527
Argument* arg;
524528
// some urls can look like line comments (parse literally - chunk would not work)
@@ -1638,6 +1642,9 @@ namespace Sass {
16381642
// lex an interpolant /#{...}/
16391643
else if (lex< exactly < hash_lbrace > >()) {
16401644
// Try to lex static expression first
1645+
if (peek< exactly< rbrace > >()) {
1646+
css_error("Invalid CSS", " after ", ": expected expression (e.g. 1px, bold), was ");
1647+
}
16411648
if (lex< re_static_expression >()) {
16421649
(*schema) << SASS_MEMORY_NEW(ctx.mem, String_Constant, pstate, lexed);
16431650
} else {
@@ -1720,7 +1727,7 @@ namespace Sass {
17201727
}
17211728
// we need to skip anything inside strings
17221729
// create a new target in parser/prelexer
1723-
if (peek < sequence < optional_spaces, exactly<rbrace> > >(p+2)) { position = p+2;
1730+
if (peek < sequence < optional_spaces, exactly<rbrace> > >(p+2)) { position = p;
17241731
css_error("Invalid CSS", " after ", ": expected expression (e.g. 1px, bold), was ");
17251732
}
17261733
const char* j = skip_over_scopes< exactly<hash_lbrace>, exactly<rbrace> >(p+2, id.end); // find the closing brace
@@ -2432,7 +2439,7 @@ namespace Sass {
24322439
// print a css parsing error with actual context information from parsed source
24332440
void Parser::css_error(const std::string& msg, const std::string& prefix, const std::string& middle)
24342441
{
2435-
int max_len = 14;
2442+
int max_len = 18;
24362443
const char* pos = peek < optional_spaces >();
24372444

24382445
const char* last_pos(pos - 1);
@@ -2443,7 +2450,7 @@ namespace Sass {
24432450
const char* pos_left(last_pos + 1);
24442451
const char* end_left(last_pos + 1);
24452452
while (pos_left > source) {
2446-
if (end_left - pos_left > max_len) {
2453+
if (end_left - pos_left >= max_len) {
24472454
ellipsis_left = true;
24482455
break;
24492456
}
@@ -2473,8 +2480,8 @@ namespace Sass {
24732480

24742481
std::string left(pos_left, end_left);
24752482
std::string right(pos_right, end_right);
2476-
if (ellipsis_left) left = ellipsis + left;
2477-
if (ellipsis_right) right = right + ellipsis;
2483+
if (ellipsis_left) left = ellipsis + left.substr(left.size() - 15);
2484+
if (ellipsis_right) right = right.substr(right.size() - 15) + ellipsis;
24782485
// now pass new message to the more generic error function
24792486
error(msg + prefix + quote(left) + middle + quote(right), pstate);
24802487
}

0 commit comments

Comments
 (0)