diff options
-rw-r--r-- | src/mongo/db/field_ref.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/field_ref_test.cpp | 11 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/mongo/db/field_ref.cpp b/src/mongo/db/field_ref.cpp index 8c74b478312..c3dbc47ed5d 100644 --- a/src/mongo/db/field_ref.cpp +++ b/src/mongo/db/field_ref.cpp @@ -25,6 +25,10 @@ namespace mongo { return; } + if (_size != 0) { + clear(); + } + // We guarantee that accesses through getPart() will be valid while 'this' is. So we // take a copy. We're going to be "chopping" up the copy into c-strings. _fieldBase.reset(new char[dottedField.size()+1]); diff --git a/src/mongo/db/field_ref_test.cpp b/src/mongo/db/field_ref_test.cpp index e84a9d1158a..cdf4aa7ad92 100644 --- a/src/mongo/db/field_ref_test.cpp +++ b/src/mongo/db/field_ref_test.cpp @@ -66,6 +66,17 @@ namespace { ASSERT_EQUALS(fieldRef.dottedField(), field); } + TEST(Normal, ParseTwice) { + string field = "a"; + FieldRef fieldRef; + for (int i = 0; i < 2; i++) { + fieldRef.parse(field); + ASSERT_EQUALS(fieldRef.numParts(), 1U); + ASSERT_EQUALS(fieldRef.getPart(0), field); + ASSERT_EQUALS(fieldRef.dottedField(), field); + } + } + TEST(Normal, MulitplePartsVariable) { const char* parts[] = {"a", "b", "c", "d", "e"}; size_t size = sizeof(parts)/sizeof(char*); |