Skip to content

Commit 15bf650

Browse files
mgreterxzyfer
authored andcommitted
Fix regression and issues with list and schema parsing
Fixes #1901 Spec sass/sass-spec#731
1 parent 826827a commit 15bf650

File tree

6 files changed

+60
-19
lines changed

6 files changed

+60
-19
lines changed

src/ast.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,7 @@ namespace Sass {
949949

950950
Selector_List* Selector_List::parentize(Selector_List* ps, Context& ctx)
951951
{
952+
if (!this->has_parent_ref()) return this;
952953
Selector_List* ss = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
953954
for (size_t pi = 0, pL = ps->length(); pi < pL; ++pi) {
954955
Selector_List* list = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
@@ -1897,6 +1898,10 @@ namespace Sass {
18971898
return false;
18981899
}
18991900

1901+
bool String_Constant::is_invisible() const {
1902+
return value_.empty() && quote_mark_ == 0;
1903+
}
1904+
19001905
bool String_Constant::operator== (const Expression& rhs) const
19011906
{
19021907
if (const String_Quoted* qstr = dynamic_cast<const String_Quoted*>(&rhs)) {

src/ast.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,7 @@ namespace Sass {
15141514
{ }
15151515
std::string type() { return "string"; }
15161516
static std::string type_name() { return "string"; }
1517+
virtual bool is_invisible() const;
15171518

15181519
virtual size_t hash()
15191520
{

src/eval.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,11 +1125,12 @@ namespace Sass {
11251125
if (List* l = dynamic_cast<List*>(ex)) {
11261126
List* ll = SASS_MEMORY_NEW(ctx.mem, List, l->pstate(), 0, l->separator());
11271127
// this fixes an issue with bourbon sample, not really sure why
1128-
if (l->size() && dynamic_cast<Null*>((*l)[0])) { res += " "; }
1128+
// if (l->size() && dynamic_cast<Null*>((*l)[0])) { res += ""; }
11291129
for(auto item : *l) {
11301130
item->is_interpolant(l->is_interpolant());
11311131
std::string rl(""); interpolation(ctx, rl, item, into_quotes, l->is_interpolant());
1132-
if (rl != "") *ll << SASS_MEMORY_NEW(ctx.mem, String_Quoted, item->pstate(), rl);
1132+
bool is_null = dynamic_cast<Null*>(item) != 0; // rl != ""
1133+
if (!is_null) *ll << SASS_MEMORY_NEW(ctx.mem, String_Quoted, item->pstate(), rl);
11331134
}
11341135
res += (ll->to_string(ctx.c_options));
11351136
ll->is_interpolant(l->is_interpolant());
@@ -1170,15 +1171,22 @@ namespace Sass {
11701171
}
11711172
}
11721173
}
1174+
bool was_quoted = false;
1175+
bool was_interpolant = false;
11731176
std::string res("");
11741177
for (size_t i = 0; i < L; ++i) {
1178+
bool is_quoted = dynamic_cast<String_Quoted*>((*s)[i]) != NULL;
11751179
(*s)[i]->perform(this);
1180+
if (was_quoted && !(*s)[i]->is_interpolant() && !was_interpolant) { res += " "; }
1181+
else if (i > 0 && is_quoted && !(*s)[i]->is_interpolant() && !was_interpolant) { res += " "; }
11761182
Expression* ex = (*s)[i]->is_delayed() ? (*s)[i] : (*s)[i]->perform(this);
11771183
interpolation(ctx, res, ex, into_quotes, ex->is_interpolant());
1184+
was_quoted = dynamic_cast<String_Quoted*>((*s)[i]) != NULL;
1185+
was_interpolant = (*s)[i]->is_interpolant();
11781186

11791187
}
11801188
if (!s->is_interpolant()) {
1181-
if (res == "") return SASS_MEMORY_NEW(ctx.mem, Null, s->pstate());
1189+
if (s->length() > 1 && res == "") return SASS_MEMORY_NEW(ctx.mem, Null, s->pstate());
11821190
return SASS_MEMORY_NEW(ctx.mem, String_Constant, s->pstate(), res);
11831191
}
11841192
String_Quoted* str = SASS_MEMORY_NEW(ctx.mem, String_Quoted, s->pstate(), res);

src/inspect.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,10 @@ namespace Sass {
406406
Expression* list_item = (*list)[i];
407407
if (output_style() != TO_SASS) {
408408
if (list_item->is_invisible()) {
409-
continue;
409+
// this fixes an issue with "" in a list
410+
if (!dynamic_cast<String_Constant*>(list_item)) {
411+
continue;
412+
}
410413
}
411414
}
412415
if (items_output) {

src/parser.cpp

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,8 @@ namespace Sass {
15911591
}
15921592

15931593
const char* e = 0;
1594+
const char* ee = end;
1595+
end = stop;
15941596
size_t num_items = 0;
15951597
bool need_space = false;
15961598
while (position < stop) {
@@ -1600,7 +1602,7 @@ namespace Sass {
16001602
}
16011603
if (need_space) {
16021604
need_space = false;
1603-
(*schema) << SASS_MEMORY_NEW(ctx.mem, String_Constant, pstate, " ");
1605+
// (*schema) << SASS_MEMORY_NEW(ctx.mem, String_Constant, pstate, " ");
16041606
}
16051607
if ((e = peek< re_functional >()) && e < stop) {
16061608
(*schema) << parse_function_call();
@@ -1627,19 +1629,22 @@ namespace Sass {
16271629
else if (lex< alternatives < exactly<'%'>, exactly < '-' >, exactly < '+' > > >()) {
16281630
(*schema) << SASS_MEMORY_NEW(ctx.mem, String_Constant, pstate, lexed);
16291631
}
1630-
else if (lex< sequence < identifier > >()) {
1631-
(*schema) << SASS_MEMORY_NEW(ctx.mem, String_Constant, pstate, lexed);
1632+
// lex a quoted string
1633+
else if (lex< quoted_string >()) {
1634+
// need_space = true;
1635+
// if (schema->length()) (*schema) << SASS_MEMORY_NEW(ctx.mem, String_Constant, pstate, " ");
1636+
// else need_space = true;
1637+
(*schema) << parse_string();
16321638
if ((*position == '"' || *position == '\'') || peek < alternatives < alpha > >()) {
1633-
need_space = true;
1639+
// need_space = true;
16341640
}
1641+
if (peek < exactly < '-' > >()) break;
16351642
}
1636-
// lex a quoted string
1637-
else if (lex< quoted_string >()) {
1638-
(*schema) << SASS_MEMORY_NEW(ctx.mem, String_Quoted, pstate, lexed, '"');
1643+
else if (lex< sequence < identifier > >()) {
1644+
(*schema) << SASS_MEMORY_NEW(ctx.mem, String_Constant, pstate, lexed);
16391645
if ((*position == '"' || *position == '\'') || peek < alternatives < alpha > >()) {
1640-
need_space = true;
1646+
// need_space = true;
16411647
}
1642-
if (peek < exactly < '-' > >()) return schema;
16431648
}
16441649
// lex (normalized) variable
16451650
else if (lex< variable >()) {
@@ -1670,10 +1675,15 @@ namespace Sass {
16701675
(*schema) << parse_factor();
16711676
}
16721677
else {
1673-
return schema;
1678+
break;
16741679
}
16751680
++num_items;
16761681
}
1682+
if (position != stop) {
1683+
(*schema) << SASS_MEMORY_NEW(ctx.mem, String_Constant, pstate, std::string(position, stop));
1684+
position = stop;
1685+
}
1686+
end = ee;
16771687
return schema;
16781688
}
16791689

@@ -2387,19 +2397,27 @@ namespace Sass {
23872397
non_greedy <
23882398
alternatives <
23892399
// consume whitespace
2390-
block_comment, spaces,
2400+
block_comment, // spaces,
23912401
// main tokens
2392-
interpolant,
2402+
sequence <
2403+
interpolant,
2404+
optional <
2405+
quoted_string
2406+
>
2407+
>,
23932408
identifier,
23942409
variable,
23952410
// issue #442
23962411
sequence <
23972412
parenthese_scope,
2398-
interpolant
2413+
interpolant,
2414+
optional <
2415+
quoted_string
2416+
>
23992417
>
24002418
>,
24012419
sequence <
2402-
optional_spaces,
2420+
// optional_spaces,
24032421
alternatives <
24042422
exactly<'{'>,
24052423
exactly<'}'>,

src/parser.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ namespace Sass {
116116
const char* it_before_token = sneak < mx >(start);
117117

118118
// match the given prelexer
119-
return mx(it_before_token);
119+
const char* match = mx(it_before_token);
120+
121+
// check if match is in valid range
122+
return match <= end ? match : 0;
120123

121124
}
122125

@@ -142,6 +145,9 @@ namespace Sass {
142145
// now call matcher to get position after token
143146
const char* it_after_token = mx(it_before_token);
144147

148+
// check if match is in valid range
149+
if (it_after_token > end) return 0;
150+
145151
// maybe we want to update the parser state anyway?
146152
if (force == false) {
147153
// assertion that we got a valid match

0 commit comments

Comments
 (0)