Skip to content

Commit

Permalink
Merge pull request #2183 from IgorStepanov/fix-bson-comparing
Browse files Browse the repository at this point in the history
fix Bson.opEquals: order of object keys is not determined
  • Loading branch information
wilzbach authored Jul 15, 2018
2 parents e623d80 + b252cfe commit 94729e7
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions data/vibe/data/bson.d
Original file line number Diff line number Diff line change
Expand Up @@ -754,12 +754,28 @@ struct Bson {
///
bool opEquals(ref const Bson other) const {
if( m_type != other.m_type ) return false;
return m_data == other.m_data;
if (m_type != Type.object)
return m_data == other.m_data;

if (m_data == other.m_data)
return true;
// Similar objects can have a different key order, but they must have a same length
if (m_data.length != other.m_data.length)
return false;

foreach (k, ref v; this.byKeyValue)
{
if (other[k] != v)
return false;
}

return true;
}
/// ditto
bool opEquals(const Bson other) const {
if( m_type != other.m_type ) return false;
return m_data == other.m_data;

return opEquals(other);
}

private void checkType(in Type[] valid_types...)
Expand Down

0 comments on commit 94729e7

Please sign in to comment.