Commit 4fdd805c authored by miloyip@gmail.com's avatar miloyip@gmail.com

Fixed issue 18 from 0.1x branch

git-svn-id: https://rapidjson.googlecode.com/svn/trunk@64 c5894555-1306-4e8d-425f-1f6f381ee07c
parent 3d77ef8e
......@@ -298,9 +298,9 @@ public:
RAPIDJSON_ASSERT(data_.o.size > 0);
RAPIDJSON_ASSERT(data_.o.members != 0);
if (data_.o.size > 1) {
Member* last = data_.o.members + (data_.o.size - 1);
if (data_.o.size > 1 && m != last) {
// Move the last one to this place
Member* last = data_.o.members + (data_.o.size - 1);
m->name = last->name;
m->value = last->value;
}
......
......@@ -576,3 +576,17 @@ TEST(Value, BigNestedObject) {
}
}
}
// Issue 18: Error removing last element of object
// http://code.google.com/p/rapidjson/issues/detail?id=18
TEST(Value, RemoveLastElement) {
rapidjson::Document doc;
rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
rapidjson::Value objVal(rapidjson::kObjectType);
objVal.AddMember("var1", 123, allocator);
objVal.AddMember("var2", "444", allocator);
objVal.AddMember("var3", 555, allocator);
EXPECT_TRUE(objVal.HasMember("var3"));
objVal.RemoveMember("var3"); // Assertion here in r61
EXPECT_FALSE(objVal.HasMember("var3"));
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment