Skip to content

Commit 390a1bb

Browse files
committed
Fix issue with invalid duplicate keys
Keys `1` and `1px` were considered duplicates if they end up in the same bucket. In sass these are indeed equal but that does not seem to apply when used as hash keys.
1 parent da4e60f commit 390a1bb

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/ast.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,21 @@ namespace Sass {
20002000
return false;
20012001
}
20022002

2003+
bool Number::eq (const Expression& rhs) const
2004+
{
2005+
if (const Number* r = dynamic_cast<const Number*>(&rhs)) {
2006+
size_t lhs_units = numerator_units_.size() + denominator_units_.size();
2007+
size_t rhs_units = r->numerator_units_.size() + r->denominator_units_.size();
2008+
if (!lhs_units && !rhs_units) {
2009+
return std::fabs(value() - r->value()) < NUMBER_EPSILON;
2010+
}
2011+
return (numerator_units_ == r->numerator_units_) &&
2012+
(denominator_units_ == r->denominator_units_) &&
2013+
std::fabs(value() - r->value()) < NUMBER_EPSILON;
2014+
}
2015+
return false;
2016+
}
2017+
20032018
bool Number::operator== (const Expression& rhs) const
20042019
{
20052020
if (const Number* r = dynamic_cast<const Number*>(&rhs)) {

src/ast.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ namespace Sass {
152152
static std::string type_name() { return ""; }
153153
virtual bool is_false() { return false; }
154154
virtual bool operator== (const Expression& rhs) const { return false; }
155+
virtual bool eq(const Expression& rhs) const { return *this == rhs; };
155156
virtual void set_delayed(bool delayed) { is_delayed(delayed); }
156157
virtual bool has_interpolant() const { return is_interpolant(); }
157158
virtual bool is_left_interpolant() const { return is_interpolant(); }
@@ -289,7 +290,7 @@ namespace Sass {
289290
};
290291
struct CompareExpression {
291292
bool operator()(const Expression* lhs, const Expression* rhs) const {
292-
return lhs && rhs && *lhs == *rhs;
293+
return lhs && rhs && lhs->eq(*rhs);
293294
}
294295
};
295296
typedef std::unordered_map<
@@ -1371,6 +1372,7 @@ namespace Sass {
13711372

13721373
virtual bool operator< (const Number& rhs) const;
13731374
virtual bool operator== (const Expression& rhs) const;
1375+
virtual bool eq(const Expression& rhs) const;
13741376

13751377
ATTACH_OPERATIONS()
13761378
};

0 commit comments

Comments
 (0)