Skip to content

Commit

Permalink
Fixed bug in 0.98.3 with key comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Jan 25, 2016
1 parent d0a0b3e commit 6573a2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/jsoncons/json_structures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,13 @@ class compare_with_string
bool operator()(const ValueT& a, const CharT* b) const
{
size_t len = std::min JSONCONS_NO_MACRO_EXP(a.name().length(),length_);
return std::char_traits<CharT>::compare(a.name().c_str(),b,len) < 0;
int result = std::char_traits<CharT>::compare(a.name().data(),b,len);
if (result < 0 || result > 0)
{
return result < 0;
}

return a.name().length() < length_;
}
};

Expand Down
11 changes: 11 additions & 0 deletions test_suite/src/json_accessor_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ BOOST_AUTO_TEST_CASE(test_object_key_proxy)
BOOST_CHECK(a.is_null());
}

BOOST_AUTO_TEST_CASE(test_compare_with_string)
{
json a;
a["key"] = "value";
a["key1"] = "value1";
a["key2"] = "value2";
BOOST_CHECK(a["key"] == a["key"]);
BOOST_CHECK(!(a["key"] == a["key1"]));
BOOST_CHECK(!(a["key"] == a["key2"]));
}

BOOST_AUTO_TEST_CASE(test_count)
{
json a;
Expand Down

0 comments on commit 6573a2f

Please sign in to comment.