Skip to content

Commit

Permalink
Fix duplicate key handling for maps
Browse files Browse the repository at this point in the history
Deferred check from parser to evaluation
Fixes #1187
  • Loading branch information
mgreter committed May 12, 2015
1 parent 8ca8816 commit 2eef52a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
7 changes: 7 additions & 0 deletions eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,13 @@ namespace Sass {
for (auto key : m->keys()) {
*mm << std::make_pair(key->perform(this), m->at(key)->perform(this));
}

// check for duplicate keys
if (mm->has_duplicate_key()) {
To_String to_string(&ctx);
error("Duplicate key \"" + mm->get_duplicate_key()->perform(&to_string) + "\" in map " + m->perform(&to_string) + ".", m->pstate());
}

mm->is_expanded(true);
return mm;
}
Expand Down
15 changes: 11 additions & 4 deletions parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ namespace Sass {

Expression* Parser::parse_map()
{
To_String to_string(&ctx);
ParserState opstate = pstate;
Expression* key = parse_list();
if (String_Quoted* str = dynamic_cast<String_Quoted*>(key)) {
if (!str->quote_mark() && !str->is_delayed()) {
Expand All @@ -1035,7 +1035,7 @@ namespace Sass {

Expression* value = parse_space_list();

Map* map = new (ctx.mem) Map(pstate, 1);
Map* map = new (ctx.mem) Map(opstate, 1);
(*map) << make_pair(key, value);

while (lex_css< exactly<','> >())
Expand Down Expand Up @@ -1064,8 +1064,15 @@ namespace Sass {
(*map) << make_pair(key, value);
}

if (map->has_duplicate_key())
{ error("Duplicate key \"" + map->get_duplicate_key()->perform(&to_string) + "\" in map " + map->perform(&to_string) + ".", pstate); }
// Check was moved to eval step
// if (map->has_duplicate_key()) {
// To_String to_string(&ctx);
// error("Duplicate key \"" + map->get_duplicate_key()->perform(&to_string) + "\" in map " + map->perform(&to_string) + ".", pstate);
// }

ParserState ps = map->pstate();
ps.offset = pstate - ps + pstate.offset;
map->pstate(ps);

return map;
}
Expand Down

0 comments on commit 2eef52a

Please sign in to comment.