summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_path_support_test.cpp
diff options
context:
space:
mode:
authorMatt Boros <matt.boros@mongodb.com>2023-05-01 16:30:27 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-05-01 17:35:37 +0000
commit56ec2520cf1f64f9e4e37fd999fa4fc224bd894a (patch)
treed8849cbb5a5eda4820482fa09bef8ed6a737b162 /src/mongo/db/pipeline/document_path_support_test.cpp
parent014850f5f9d0e2cd9490755e94fe7a17570f7a70 (diff)
downloadmongo-56ec2520cf1f64f9e4e37fd999fa4fc224bd894a.tar.gz
SERVER-76470 Restrict classic $lookup localField 0-prefixed numeric component from acting as array index
Diffstat (limited to 'src/mongo/db/pipeline/document_path_support_test.cpp')
-rw-r--r--src/mongo/db/pipeline/document_path_support_test.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/document_path_support_test.cpp b/src/mongo/db/pipeline/document_path_support_test.cpp
index a33b1ae5d48..f9071de09c6 100644
--- a/src/mongo/db/pipeline/document_path_support_test.cpp
+++ b/src/mongo/db/pipeline/document_path_support_test.cpp
@@ -310,6 +310,27 @@ TEST(VisitAllValuesAtPathTest, DoesNotAddMissingValueWithinArrayToResults) {
ASSERT_EQ(values.count(Value(2)), 1UL);
}
+TEST(VisitAllValuesAtPathTest, StrictNumericFields) {
+ auto values = kDefaultValueComparator.makeUnorderedValueSet();
+ auto callback = [&values](const Value& val) {
+ values.insert(val);
+ };
+ {
+ Document doc(fromjson("{a: [[], [{b: [3]}, {b: {\"00\": 2}}]]}"));
+ visitAllValuesAtPath(doc, FieldPath("a.1.b.00"), callback);
+ // We only find 2.
+ ASSERT_EQ(values.size(), 1UL);
+ ASSERT_EQ(values.count(Value(2)), 1UL);
+ }
+ {
+ // Test a 0-prefixed case other than "00".
+ Document doc(fromjson("{a: [{b: [0, 1]}, {b: {\"01\": 2}}]}"));
+ visitAllValuesAtPath(doc, FieldPath("a.b.01"), callback);
+ ASSERT_EQ(values.size(), 1UL);
+ ASSERT_EQ(values.count(Value(2)), 1UL);
+ }
+}
+
TEST(ExtractElementAlongNonArrayPathTest, ReturnsMissingIfPathDoesNotExist) {
Document doc{{"a", 1}, {"b", 2}};
auto result = extractElementAlongNonArrayPath(doc, FieldPath{"c.d"});