summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/matcher')
-rw-r--r--src/mongo/db/matcher/SConscript1
-rw-r--r--src/mongo/db/matcher/copyable_match_expression.h28
-rw-r--r--src/mongo/db/matcher/expression_algo_test.cpp88
-rw-r--r--src/mongo/db/matcher/expression_geo_test.cpp1
-rw-r--r--src/mongo/db/matcher/expression_parser.cpp142
-rw-r--r--src/mongo/db/matcher/expression_parser.h49
-rw-r--r--src/mongo/db/matcher/expression_parser_array_test.cpp135
-rw-r--r--src/mongo/db/matcher/expression_parser_geo_test.cpp238
-rw-r--r--src/mongo/db/matcher/expression_parser_leaf_test.cpp1134
-rw-r--r--src/mongo/db/matcher/expression_parser_test.cpp157
-rw-r--r--src/mongo/db/matcher/expression_parser_tree.cpp8
-rw-r--r--src/mongo/db/matcher/expression_parser_tree_test.cpp19
-rw-r--r--src/mongo/db/matcher/expression_serialization_test.cpp980
-rw-r--r--src/mongo/db/matcher/expression_text.h15
-rw-r--r--src/mongo/db/matcher/expression_text_base.h15
-rw-r--r--src/mongo/db/matcher/expression_text_noop.h4
-rw-r--r--src/mongo/db/matcher/expression_where_noop.cpp2
-rw-r--r--src/mongo/db/matcher/expression_with_placeholder.cpp5
-rw-r--r--src/mongo/db/matcher/expression_with_placeholder_test.cpp16
-rw-r--r--src/mongo/db/matcher/extensions_callback_disallow_extensions.cpp44
-rw-r--r--src/mongo/db/matcher/extensions_callback_disallow_extensions.h53
-rw-r--r--src/mongo/db/matcher/matcher.cpp8
-rw-r--r--src/mongo/db/matcher/matcher.h8
-rw-r--r--src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index_test.cpp19
-rw-r--r--src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties_test.cpp16
-rw-r--r--src/mongo/db/matcher/schema/expression_internal_schema_cond_test.cpp10
-rw-r--r--src/mongo/db/matcher/schema/expression_internal_schema_match_array_index_test.cpp25
-rw-r--r--src/mongo/db/matcher/schema/expression_internal_schema_object_match_test.cpp28
-rw-r--r--src/mongo/db/matcher/schema/expression_internal_schema_xor_test.cpp10
-rw-r--r--src/mongo/db/matcher/schema/expression_parser_schema_test.cpp397
30 files changed, 1932 insertions, 1723 deletions
diff --git a/src/mongo/db/matcher/SConscript b/src/mongo/db/matcher/SConscript
index e8c9146cf69..8d8b89496bd 100644
--- a/src/mongo/db/matcher/SConscript
+++ b/src/mongo/db/matcher/SConscript
@@ -43,7 +43,6 @@ env.Library(
'expression_where_noop.cpp',
'expression_with_placeholder.cpp',
'extensions_callback.cpp',
- 'extensions_callback_disallow_extensions.cpp',
'extensions_callback_noop.cpp',
'match_details.cpp',
'matchable.cpp',
diff --git a/src/mongo/db/matcher/copyable_match_expression.h b/src/mongo/db/matcher/copyable_match_expression.h
index 9f17fd1b082..8961dce131d 100644
--- a/src/mongo/db/matcher/copyable_match_expression.h
+++ b/src/mongo/db/matcher/copyable_match_expression.h
@@ -29,6 +29,7 @@
#pragma once
#include "mongo/db/matcher/expression_parser.h"
+#include "mongo/db/matcher/extensions_callback_noop.h"
namespace mongo {
@@ -50,11 +51,15 @@ public:
* encounter an error.
*/
CopyableMatchExpression(BSONObj matchAST,
- std::unique_ptr<const ExtensionsCallback> extensionsCallback,
- const CollatorInterface* collator)
+ const CollatorInterface* collator,
+ const boost::intrusive_ptr<ExpressionContext>& expCtx = nullptr,
+ std::unique_ptr<const ExtensionsCallback> extensionsCallback =
+ stdx::make_unique<ExtensionsCallbackNoop>(),
+ MatchExpressionParser::AllowedFeatureSet allowedFeatures =
+ MatchExpressionParser::kBanAllSpecialFeatures)
: _matchAST(matchAST), _extensionsCallback(std::move(extensionsCallback)) {
- StatusWithMatchExpression parseResult =
- MatchExpressionParser::parse(_matchAST, *_extensionsCallback, collator);
+ StatusWithMatchExpression parseResult = MatchExpressionParser::parse(
+ _matchAST, collator, expCtx, *_extensionsCallback, allowedFeatures);
uassertStatusOK(parseResult.getStatus());
_matchExpr = std::move(parseResult.getValue());
}
@@ -67,9 +72,18 @@ public:
* if there other CopyableMatchExpression objects referencing this MatchExpression, they don't
* see the change in collator.
*/
- void setCollator(const CollatorInterface* collator) {
- StatusWithMatchExpression parseResult =
- MatchExpressionParser::parse(_matchAST, *_extensionsCallback, collator);
+ void setCollator(const CollatorInterface* collator,
+ const boost::intrusive_ptr<ExpressionContext>& expCtx = nullptr) {
+ // We can allow all features because any features that were allowed in the original
+ // MatchExpression construction should be allowed now.
+ MatchExpressionParser::AllowedFeatureSet allowedFeatures =
+ MatchExpressionParser::kAllowAllSpecialFeatures;
+ if (!expCtx) {
+ allowedFeatures = allowedFeatures & ~MatchExpressionParser::AllowedFeatures::kExpr;
+ }
+
+ StatusWithMatchExpression parseResult = MatchExpressionParser::parse(
+ _matchAST, collator, expCtx, *_extensionsCallback, allowedFeatures);
invariantOK(parseResult.getStatus());
_matchExpr = std::move(parseResult.getValue());
}
diff --git a/src/mongo/db/matcher/expression_algo_test.cpp b/src/mongo/db/matcher/expression_algo_test.cpp
index c01f77a183b..b97146bc08b 100644
--- a/src/mongo/db/matcher/expression_algo_test.cpp
+++ b/src/mongo/db/matcher/expression_algo_test.cpp
@@ -37,8 +37,6 @@
#include "mongo/db/matcher/expression.h"
#include "mongo/db/matcher/expression_algo.h"
#include "mongo/db/matcher/expression_parser.h"
-#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
-#include "mongo/db/matcher/extensions_callback_noop.h"
#include "mongo/db/query/collation/collator_interface_mock.h"
#include "mongo/platform/decimal128.h"
@@ -54,8 +52,7 @@ class ParsedMatchExpression {
public:
ParsedMatchExpression(const std::string& str, const CollatorInterface* collator = nullptr)
: _obj(fromjson(str)) {
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(_obj, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(_obj, collator);
ASSERT_OK(result.getStatus());
_expr = std::move(result.getValue());
}
@@ -74,10 +71,8 @@ TEST(ExpressionAlgoIsSubsetOf, NullAndOmittedField) {
// an Undefined type.
BSONObj undefined = fromjson("{a: undefined}");
const CollatorInterface* collator = nullptr;
- ASSERT_EQUALS(
- ErrorCodes::BadValue,
- MatchExpressionParser::parse(undefined, ExtensionsCallbackDisallowExtensions(), collator)
- .getStatus());
+ ASSERT_EQUALS(ErrorCodes::BadValue,
+ MatchExpressionParser::parse(undefined, collator).getStatus());
ParsedMatchExpression empty("{}");
ParsedMatchExpression null("{a: null}");
@@ -714,8 +709,7 @@ TEST(ExpressionAlgoIsSubsetOf, NonMatchingCollationsNoStringComparison) {
TEST(IsIndependent, AndIsIndependentOnlyIfChildrenAre) {
BSONObj matchPredicate = fromjson("{$and: [{a: 1}, {b: 1}]}");
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression status =
- MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ StatusWithMatchExpression status = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(status.getStatus());
unique_ptr<MatchExpression> expr = std::move(status.getValue());
@@ -726,8 +720,7 @@ TEST(IsIndependent, AndIsIndependentOnlyIfChildrenAre) {
TEST(IsIndependent, ElemMatchIsNotIndependent) {
BSONObj matchPredicate = fromjson("{x: {$elemMatch: {y: 1}}}");
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression status =
- MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ StatusWithMatchExpression status = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(status.getStatus());
unique_ptr<MatchExpression> expr = std::move(status.getValue());
@@ -739,8 +732,7 @@ TEST(IsIndependent, ElemMatchIsNotIndependent) {
TEST(IsIndependent, NorIsIndependentOnlyIfChildrenAre) {
BSONObj matchPredicate = fromjson("{$nor: [{a: 1}, {b: 1}]}");
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression status =
- MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ StatusWithMatchExpression status = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(status.getStatus());
unique_ptr<MatchExpression> expr = std::move(status.getValue());
@@ -751,8 +743,7 @@ TEST(IsIndependent, NorIsIndependentOnlyIfChildrenAre) {
TEST(IsIndependent, NotIsIndependentOnlyIfChildrenAre) {
BSONObj matchPredicate = fromjson("{a: {$not: {$eq: 1}}}");
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression status =
- MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ StatusWithMatchExpression status = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(status.getStatus());
unique_ptr<MatchExpression> expr = std::move(status.getValue());
@@ -763,8 +754,7 @@ TEST(IsIndependent, NotIsIndependentOnlyIfChildrenAre) {
TEST(IsIndependent, OrIsIndependentOnlyIfChildrenAre) {
BSONObj matchPredicate = fromjson("{$or: [{a: 1}, {b: 1}]}");
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression status =
- MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ StatusWithMatchExpression status = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(status.getStatus());
unique_ptr<MatchExpression> expr = std::move(status.getValue());
@@ -775,8 +765,7 @@ TEST(IsIndependent, OrIsIndependentOnlyIfChildrenAre) {
TEST(IsIndependent, AndWithDottedFieldPathsIsNotIndependent) {
BSONObj matchPredicate = fromjson("{$and: [{'a': 1}, {'a.b': 1}]}");
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression status =
- MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ StatusWithMatchExpression status = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(status.getStatus());
unique_ptr<MatchExpression> expr = std::move(status.getValue());
@@ -787,8 +776,7 @@ TEST(IsIndependent, AndWithDottedFieldPathsIsNotIndependent) {
TEST(IsIndependent, BallIsIndependentOfBalloon) {
BSONObj matchPredicate = fromjson("{'a.ball': 4}");
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression status =
- MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ StatusWithMatchExpression status = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(status.getStatus());
unique_ptr<MatchExpression> expr = std::move(status.getValue());
@@ -800,8 +788,7 @@ TEST(IsIndependent, BallIsIndependentOfBalloon) {
TEST(SplitMatchExpression, AndWithSplittableChildrenIsSplittable) {
BSONObj matchPredicate = fromjson("{$and: [{a: 1}, {b: 1}]}");
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression status =
- MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ StatusWithMatchExpression status = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(status.getStatus());
std::pair<unique_ptr<MatchExpression>, unique_ptr<MatchExpression>> splitExpr =
@@ -822,8 +809,7 @@ TEST(SplitMatchExpression, AndWithSplittableChildrenIsSplittable) {
TEST(SplitMatchExpression, NorWithIndependentChildrenIsSplittable) {
BSONObj matchPredicate = fromjson("{$nor: [{a: 1}, {b: 1}]}");
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression status =
- MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ StatusWithMatchExpression status = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(status.getStatus());
std::pair<unique_ptr<MatchExpression>, unique_ptr<MatchExpression>> splitExpr =
@@ -844,8 +830,7 @@ TEST(SplitMatchExpression, NorWithIndependentChildrenIsSplittable) {
TEST(SplitMatchExpression, NotWithIndependentChildIsSplittable) {
BSONObj matchPredicate = fromjson("{x: {$not: {$gt: 4}}}");
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression status =
- MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ StatusWithMatchExpression status = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(status.getStatus());
std::pair<unique_ptr<MatchExpression>, unique_ptr<MatchExpression>> splitExpr =
@@ -862,8 +847,7 @@ TEST(SplitMatchExpression, NotWithIndependentChildIsSplittable) {
TEST(SplitMatchExpression, OrWithOnlyIndependentChildrenIsNotSplittable) {
BSONObj matchPredicate = fromjson("{$or: [{a: 1}, {b: 1}]}");
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression status =
- MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ StatusWithMatchExpression status = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(status.getStatus());
std::pair<unique_ptr<MatchExpression>, unique_ptr<MatchExpression>> splitExpr =
@@ -883,8 +867,7 @@ TEST(SplitMatchExpression, ComplexMatchExpressionSplitsCorrectly) {
"{$or: [{'a.b' : 3}, {'a.b.c': 4}]},"
"{$nor: [{x: {$gt: 4}}, {$and: [{x: {$not: {$eq: 1}}}, {y: 3}]}]}]}");
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression status =
- MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ StatusWithMatchExpression status = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(status.getStatus());
std::pair<unique_ptr<MatchExpression>, unique_ptr<MatchExpression>> splitExpr =
@@ -909,8 +892,7 @@ TEST(SplitMatchExpression, ComplexMatchExpressionSplitsCorrectly) {
TEST(SplitMatchExpression, ShouldNotExtractPrefixOfDottedPathAsIndependent) {
BSONObj matchPredicate = fromjson("{$and: [{a: 1}, {'a.b': 1}, {'a.c': 1}]}");
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression status =
- MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ StatusWithMatchExpression status = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(status.getStatus());
std::pair<unique_ptr<MatchExpression>, unique_ptr<MatchExpression>> splitExpr =
@@ -931,7 +913,7 @@ TEST(SplitMatchExpression, ShouldNotExtractPrefixOfDottedPathAsIndependent) {
TEST(SplitMatchExpression, ShouldMoveIndependentLeafPredicateAcrossRename) {
BSONObj matchPredicate = fromjson("{a: 1}");
const CollatorInterface* collator = nullptr;
- auto matcher = MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ auto matcher = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(matcher.getStatus());
StringMap<std::string> renames{{"a", "b"}};
@@ -949,7 +931,7 @@ TEST(SplitMatchExpression, ShouldMoveIndependentLeafPredicateAcrossRename) {
TEST(SplitMatchExpression, ShouldMoveIndependentAndPredicateAcrossRename) {
BSONObj matchPredicate = fromjson("{$and: [{a: 1}, {b: 2}]}");
const CollatorInterface* collator = nullptr;
- auto matcher = MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ auto matcher = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(matcher.getStatus());
StringMap<std::string> renames{{"a", "c"}};
@@ -967,7 +949,7 @@ TEST(SplitMatchExpression, ShouldMoveIndependentAndPredicateAcrossRename) {
TEST(SplitMatchExpression, ShouldSplitPartiallyDependentAndPredicateAcrossRename) {
BSONObj matchPredicate = fromjson("{$and: [{a: 1}, {b: 2}]}");
const CollatorInterface* collator = nullptr;
- auto matcher = MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ auto matcher = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(matcher.getStatus());
StringMap<std::string> renames{{"a", "c"}};
@@ -988,7 +970,7 @@ TEST(SplitMatchExpression, ShouldSplitPartiallyDependentAndPredicateAcrossRename
TEST(SplitMatchExpression, ShouldSplitPartiallyDependentComplexPredicateMultipleRenames) {
BSONObj matchPredicate = fromjson("{$and: [{a: 1}, {$or: [{b: 2}, {c: 3}]}]}");
const CollatorInterface* collator = nullptr;
- auto matcher = MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ auto matcher = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(matcher.getStatus());
StringMap<std::string> renames{{"b", "d"}, {"c", "e"}};
@@ -1010,7 +992,7 @@ TEST(SplitMatchExpression,
ShouldSplitPartiallyDependentComplexPredicateMultipleRenamesDottedPaths) {
BSONObj matchPredicate = fromjson("{$and: [{a: 1}, {$or: [{'d.e.f': 2}, {'e.f.g': 3}]}]}");
const CollatorInterface* collator = nullptr;
- auto matcher = MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ auto matcher = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(matcher.getStatus());
StringMap<std::string> renames{{"d.e.f", "x"}, {"e.f.g", "y"}};
@@ -1031,7 +1013,7 @@ TEST(SplitMatchExpression,
TEST(SplitMatchExpression, ShouldNotMoveElemMatchObjectAcrossRename) {
BSONObj matchPredicate = fromjson("{a: {$elemMatch: {b: 3}}}");
const CollatorInterface* collator = nullptr;
- auto matcher = MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ auto matcher = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(matcher.getStatus());
StringMap<std::string> renames{{"a", "c"}};
@@ -1049,7 +1031,7 @@ TEST(SplitMatchExpression, ShouldNotMoveElemMatchObjectAcrossRename) {
TEST(SplitMatchExpression, ShouldNotMoveElemMatchValueAcrossRename) {
BSONObj matchPredicate = fromjson("{a: {$elemMatch: {$eq: 3}}}");
const CollatorInterface* collator = nullptr;
- auto matcher = MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ auto matcher = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(matcher.getStatus());
StringMap<std::string> renames{{"a", "c"}};
@@ -1067,7 +1049,7 @@ TEST(SplitMatchExpression, ShouldNotMoveElemMatchValueAcrossRename) {
TEST(SplitMatchExpression, ShouldMoveTypeAcrossRename) {
BSONObj matchPredicate = fromjson("{a: {$type: 16}}");
const CollatorInterface* collator = nullptr;
- auto matcher = MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ auto matcher = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(matcher.getStatus());
StringMap<std::string> renames{{"a", "c"}};
@@ -1085,7 +1067,7 @@ TEST(SplitMatchExpression, ShouldMoveTypeAcrossRename) {
TEST(SplitMatchExpression, ShouldNotMoveSizeAcrossRename) {
BSONObj matchPredicate = fromjson("{a: {$size: 3}}");
const CollatorInterface* collator = nullptr;
- auto matcher = MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ auto matcher = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(matcher.getStatus());
StringMap<std::string> renames{{"a", "c"}};
@@ -1103,7 +1085,7 @@ TEST(SplitMatchExpression, ShouldNotMoveSizeAcrossRename) {
TEST(SplitMatchExpression, ShouldNotMoveMinItemsAcrossRename) {
BSONObj matchPredicate = fromjson("{a: {$_internalSchemaMinItems: 3}}");
const CollatorInterface* collator = nullptr;
- auto matcher = MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ auto matcher = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(matcher.getStatus());
StringMap<std::string> renames{{"a", "c"}};
@@ -1121,7 +1103,7 @@ TEST(SplitMatchExpression, ShouldNotMoveMinItemsAcrossRename) {
TEST(SplitMatchExpression, ShouldNotMoveMaxItemsAcrossRename) {
BSONObj matchPredicate = fromjson("{a: {$_internalSchemaMaxItems: 3}}");
const CollatorInterface* collator = nullptr;
- auto matcher = MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ auto matcher = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(matcher.getStatus());
StringMap<std::string> renames{{"a", "c"}};
@@ -1139,7 +1121,7 @@ TEST(SplitMatchExpression, ShouldNotMoveMaxItemsAcrossRename) {
TEST(SplitMatchExpression, ShouldMoveMinLengthAcrossRename) {
BSONObj matchPredicate = fromjson("{a: {$_internalSchemaMinLength: 3}}");
const CollatorInterface* collator = nullptr;
- auto matcher = MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ auto matcher = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(matcher.getStatus());
StringMap<std::string> renames{{"a", "c"}};
@@ -1157,7 +1139,7 @@ TEST(SplitMatchExpression, ShouldMoveMinLengthAcrossRename) {
TEST(SplitMatchExpression, ShouldMoveMaxLengthAcrossRename) {
BSONObj matchPredicate = fromjson("{a: {$_internalSchemaMaxLength: 3}}");
const CollatorInterface* collator = nullptr;
- auto matcher = MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ auto matcher = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(matcher.getStatus());
StringMap<std::string> renames{{"a", "c"}};
@@ -1175,8 +1157,7 @@ TEST(SplitMatchExpression, ShouldMoveMaxLengthAcrossRename) {
TEST(MapOverMatchExpression, DoesMapOverLogicalNodes) {
BSONObj matchPredicate = fromjson("{a: {$not: {$eq: 1}}}");
const CollatorInterface* collator = nullptr;
- auto swMatchExpression =
- MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ auto swMatchExpression = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(swMatchExpression.getStatus());
bool hasLogicalNode = false;
@@ -1194,8 +1175,7 @@ TEST(MapOverMatchExpression, DoesMapOverLogicalNodes) {
TEST(MapOverMatchExpression, DoesMapOverLeafNodes) {
BSONObj matchPredicate = fromjson("{a: {$not: {$eq: 1}}}");
const CollatorInterface* collator = nullptr;
- auto swMatchExpression =
- MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ auto swMatchExpression = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(swMatchExpression.getStatus());
bool hasLeafNode = false;
@@ -1213,8 +1193,7 @@ TEST(MapOverMatchExpression, DoesMapOverLeafNodes) {
TEST(MapOverMatchExpression, DoesPassPath) {
BSONObj matchPredicate = fromjson("{a: {$elemMatch: {b: 1}}}");
const CollatorInterface* collator = nullptr;
- auto swMatchExpression =
- MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ auto swMatchExpression = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(swMatchExpression.getStatus());
std::vector<std::string> paths;
@@ -1232,8 +1211,7 @@ TEST(MapOverMatchExpression, DoesPassPath) {
TEST(MapOverMatchExpression, DoesMapOverNodesWithMultipleChildren) {
BSONObj matchPredicate = fromjson("{$and: [{a: {$gt: 1}}, {b: {$lte: 2}}]}");
const CollatorInterface* collator = nullptr;
- auto swMatchExpression =
- MatchExpressionParser::parse(matchPredicate, ExtensionsCallbackNoop(), collator);
+ auto swMatchExpression = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(swMatchExpression.getStatus());
size_t nodeCount = 0;
diff --git a/src/mongo/db/matcher/expression_geo_test.cpp b/src/mongo/db/matcher/expression_geo_test.cpp
index 52ed8ac77e1..de7bd773c8a 100644
--- a/src/mongo/db/matcher/expression_geo_test.cpp
+++ b/src/mongo/db/matcher/expression_geo_test.cpp
@@ -36,7 +36,6 @@
#include "mongo/db/json.h"
#include "mongo/db/matcher/expression.h"
#include "mongo/db/matcher/expression_geo.h"
-#include "mongo/db/matcher/matcher.h"
#include "mongo/stdx/memory.h"
namespace mongo {
diff --git a/src/mongo/db/matcher/expression_parser.cpp b/src/mongo/db/matcher/expression_parser.cpp
index 051e6a6884c..c49382699db 100644
--- a/src/mongo/db/matcher/expression_parser.cpp
+++ b/src/mongo/db/matcher/expression_parser.cpp
@@ -102,7 +102,8 @@ StatusWithMatchExpression MatchExpressionParser::_parseComparison(
ComparisonMatchExpression* cmp,
const BSONElement& e,
const CollatorInterface* collator,
- const boost::intrusive_ptr<ExpressionContext>& expCtx) {
+ const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures) {
std::unique_ptr<ComparisonMatchExpression> temp(cmp);
// Non-equality comparison match expressions cannot have
@@ -114,8 +115,11 @@ StatusWithMatchExpression MatchExpressionParser::_parseComparison(
}
if (_isAggExpression(e, expCtx)) {
- auto expr = _parseAggExpression(e, expCtx);
- auto s = temp->init(name, expr);
+ auto expr = _parseAggExpression(e, expCtx, allowedFeatures);
+ if (!expr.isOK()) {
+ return expr.getStatus();
+ }
+ auto s = temp->init(name, expr.getValue());
if (!s.isOK()) {
return s;
}
@@ -138,12 +142,14 @@ StatusWithMatchExpression MatchExpressionParser::_parseSubField(
const BSONElement& e,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel) {
if (mongoutils::str::equals("$eq", e.fieldName()))
- return _parseComparison(name, new EqualityMatchExpression(), e, collator, expCtx);
+ return _parseComparison(
+ name, new EqualityMatchExpression(), e, collator, expCtx, allowedFeatures);
if (mongoutils::str::equals("$not", e.fieldName())) {
- return _parseNot(name, e, collator, expCtx, topLevel);
+ return _parseNot(name, e, collator, expCtx, allowedFeatures, topLevel);
}
auto parseExpMatchType = MatchExpressionParser::parsePathAcceptingKeyword(e);
@@ -159,21 +165,25 @@ StatusWithMatchExpression MatchExpressionParser::_parseSubField(
switch (*parseExpMatchType) {
case PathAcceptingKeyword::LESS_THAN:
- return _parseComparison(name, new LTMatchExpression(), e, collator, expCtx);
+ return _parseComparison(
+ name, new LTMatchExpression(), e, collator, expCtx, allowedFeatures);
case PathAcceptingKeyword::LESS_THAN_OR_EQUAL:
- return _parseComparison(name, new LTEMatchExpression(), e, collator, expCtx);
+ return _parseComparison(
+ name, new LTEMatchExpression(), e, collator, expCtx, allowedFeatures);
case PathAcceptingKeyword::GREATER_THAN:
- return _parseComparison(name, new GTMatchExpression(), e, collator, expCtx);
+ return _parseComparison(
+ name, new GTMatchExpression(), e, collator, expCtx, allowedFeatures);
case PathAcceptingKeyword::GREATER_THAN_OR_EQUAL:
- return _parseComparison(name, new GTEMatchExpression(), e, collator, expCtx);
+ return _parseComparison(
+ name, new GTEMatchExpression(), e, collator, expCtx, allowedFeatures);
case PathAcceptingKeyword::NOT_EQUAL: {
if (RegEx == e.type()) {
// Just because $ne can be rewritten as the negation of an
// equality does not mean that $ne of a regex is allowed. See SERVER-1705.
return {Status(ErrorCodes::BadValue, "Can't have regex as arg to $ne.")};
}
- StatusWithMatchExpression s =
- _parseComparison(name, new EqualityMatchExpression(), e, collator, expCtx);
+ StatusWithMatchExpression s = _parseComparison(
+ name, new EqualityMatchExpression(), e, collator, expCtx, allowedFeatures);
if (!s.isOK())
return s;
std::unique_ptr<NotMatchExpression> n = stdx::make_unique<NotMatchExpression>();
@@ -183,7 +193,8 @@ StatusWithMatchExpression MatchExpressionParser::_parseSubField(
return {std::move(n)};
}
case PathAcceptingKeyword::EQUALITY:
- return _parseComparison(name, new EqualityMatchExpression(), e, collator, expCtx);
+ return _parseComparison(
+ name, new EqualityMatchExpression(), e, collator, expCtx, allowedFeatures);
case PathAcceptingKeyword::IN_EXPR: {
if (e.type() != Array)
@@ -291,14 +302,14 @@ StatusWithMatchExpression MatchExpressionParser::_parseSubField(
}
case PathAcceptingKeyword::ELEM_MATCH:
- return _parseElemMatch(name, e, collator, expCtx, topLevel);
+ return _parseElemMatch(name, e, collator, expCtx, allowedFeatures, topLevel);
case PathAcceptingKeyword::ALL:
- return _parseAll(name, e, collator, expCtx, topLevel);
+ return _parseAll(name, e, collator, expCtx, allowedFeatures, topLevel);
case PathAcceptingKeyword::WITHIN:
case PathAcceptingKeyword::GEO_INTERSECTS:
- return _parseGeo(name, *parseExpMatchType, context);
+ return _parseGeo(name, *parseExpMatchType, context, allowedFeatures);
case PathAcceptingKeyword::GEO_NEAR:
return {Status(ErrorCodes::BadValue,
@@ -341,7 +352,7 @@ StatusWithMatchExpression MatchExpressionParser::_parseSubField(
str::stream() << "$_internalSchemaObjectMatch must be an object");
}
- auto parsedSubObjExpr = _parse(e.Obj(), collator, expCtx, topLevel);
+ auto parsedSubObjExpr = _parse(e.Obj(), collator, expCtx, allowedFeatures, topLevel);
if (!parsedSubObjExpr.isOK()) {
return parsedSubObjExpr;
}
@@ -427,7 +438,7 @@ StatusWithMatchExpression MatchExpressionParser::_parseSubField(
<< "must be an object");
}
StatusWithMatchExpression query =
- _parse(second.embeddedObject(), collator, expCtx, topLevel);
+ _parse(second.embeddedObject(), collator, expCtx, allowedFeatures, topLevel);
if (!query.isOK()) {
return query.getStatus();
}
@@ -452,6 +463,7 @@ StatusWithMatchExpression MatchExpressionParser::_parse(
const BSONObj& obj,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel) {
std::unique_ptr<AndMatchExpression> root = stdx::make_unique<AndMatchExpression>();
@@ -466,7 +478,8 @@ StatusWithMatchExpression MatchExpressionParser::_parse(
if (e.type() != Array)
return {Status(ErrorCodes::BadValue, "$or must be an array")};
std::unique_ptr<OrMatchExpression> temp = stdx::make_unique<OrMatchExpression>();
- Status s = _parseTreeList(e.Obj(), temp.get(), collator, expCtx, childIsTopLevel);
+ Status s = _parseTreeList(
+ e.Obj(), temp.get(), collator, expCtx, allowedFeatures, childIsTopLevel);
if (!s.isOK())
return s;
root->add(temp.release());
@@ -474,7 +487,8 @@ StatusWithMatchExpression MatchExpressionParser::_parse(
if (e.type() != Array)
return {Status(ErrorCodes::BadValue, "$and must be an array")};
std::unique_ptr<AndMatchExpression> temp = stdx::make_unique<AndMatchExpression>();
- Status s = _parseTreeList(e.Obj(), temp.get(), collator, expCtx, childIsTopLevel);
+ Status s = _parseTreeList(
+ e.Obj(), temp.get(), collator, expCtx, allowedFeatures, childIsTopLevel);
if (!s.isOK())
return s;
root->add(temp.release());
@@ -482,7 +496,8 @@ StatusWithMatchExpression MatchExpressionParser::_parse(
if (e.type() != Array)
return {Status(ErrorCodes::BadValue, "$nor must be an array")};
std::unique_ptr<NorMatchExpression> temp = stdx::make_unique<NorMatchExpression>();
- Status s = _parseTreeList(e.Obj(), temp.get(), collator, expCtx, childIsTopLevel);
+ Status s = _parseTreeList(
+ e.Obj(), temp.get(), collator, expCtx, allowedFeatures, childIsTopLevel);
if (!s.isOK())
return s;
root->add(temp.release());
@@ -494,11 +509,19 @@ StatusWithMatchExpression MatchExpressionParser::_parse(
// Don't do anything with the expression; CanonicalQuery::init() will look through
// the BSONObj again for a $atomic/$isolated.
} else if (mongoutils::str::equals("where", rest)) {
+ if ((allowedFeatures & AllowedFeatures::kJavascript) == 0u) {
+ return {Status(ErrorCodes::BadValue, "$where is not allowed in this context")};
+ }
+
StatusWithMatchExpression s = _extensionsCallback->parseWhere(e);
if (!s.isOK())
return s;
root->add(s.getValue().release());
} else if (mongoutils::str::equals("text", rest)) {
+ if ((allowedFeatures & AllowedFeatures::kText) == 0u) {
+ return {Status(ErrorCodes::BadValue, "$text is not allowed in this context")};
+ }
+
StatusWithMatchExpression s = _extensionsCallback->parseText(e);
if (!s.isOK()) {
return s;
@@ -526,7 +549,11 @@ StatusWithMatchExpression MatchExpressionParser::_parse(
} else if (mongoutils::str::equals("_internalSchemaCond", rest)) {
auto condExpr =
_parseInternalSchemaFixedArityArgument<InternalSchemaCondMatchExpression>(
- InternalSchemaCondMatchExpression::kName, e, collator, expCtx);
+ InternalSchemaCondMatchExpression::kName,
+ e,
+ collator,
+ expCtx,
+ allowedFeatures);
if (!condExpr.isOK()) {
return condExpr.getStatus();
}
@@ -537,8 +564,8 @@ StatusWithMatchExpression MatchExpressionParser::_parse(
return {
Status(ErrorCodes::TypeMismatch, "$_internalSchemaXor must be an array")};
auto xorExpr = stdx::make_unique<InternalSchemaXorMatchExpression>();
- Status s =
- _parseTreeList(e.Obj(), xorExpr.get(), collator, expCtx, childIsTopLevel);
+ Status s = _parseTreeList(
+ e.Obj(), xorExpr.get(), collator, expCtx, allowedFeatures, childIsTopLevel);
if (!s.isOK())
return s;
root->add(xorExpr.release());
@@ -587,8 +614,13 @@ StatusWithMatchExpression MatchExpressionParser::_parse(
}
if (_isExpressionDocument(e, false, expCtx)) {
- Status s =
- _parseSub(e.fieldName(), e.Obj(), root.get(), collator, expCtx, childIsTopLevel);
+ Status s = _parseSub(e.fieldName(),
+ e.Obj(),
+ root.get(),
+ collator,
+ expCtx,
+ allowedFeatures,
+ childIsTopLevel);
if (!s.isOK())
return s;
continue;
@@ -602,8 +634,8 @@ StatusWithMatchExpression MatchExpressionParser::_parse(
continue;
}
- auto eq =
- _parseComparison(e.fieldName(), new EqualityMatchExpression(), e, collator, expCtx);
+ auto eq = _parseComparison(
+ e.fieldName(), new EqualityMatchExpression(), e, collator, expCtx, allowedFeatures);
if (!eq.isOK())
return eq;
@@ -624,6 +656,7 @@ Status MatchExpressionParser::_parseSub(const char* name,
AndMatchExpression* root,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel) {
// The one exception to {field : {fully contained argument} } is, of course, geo. Example:
// sub == { field : {$near[Sphere]: [0,0], $maxDistance: 1000, $minDistance: 10 } }
@@ -638,17 +671,10 @@ Status MatchExpressionParser::_parseSub(const char* name,
if (geoIt.more()) {
BSONElement firstElt = geoIt.next();
if (firstElt.isABSONObj()) {
- const char* fieldName = firstElt.fieldName();
- // TODO: Having these $fields here isn't ideal but we don't want to pull in anything
- // from db/geo at this point, since it may not actually be linked in...
- if (mongoutils::str::equals(fieldName, "$near") ||
- mongoutils::str::equals(fieldName, "$nearSphere") ||
- mongoutils::str::equals(fieldName, "$geoNear")) {
+ if (MatchExpressionParser::parsePathAcceptingKeyword(firstElt) ==
+ PathAcceptingKeyword::GEO_NEAR) {
StatusWithMatchExpression s =
- _parseGeo(name,
- *MatchExpressionParser::parsePathAcceptingKeyword(
- firstElt, PathAcceptingKeyword::EQUALITY),
- sub);
+ _parseGeo(name, PathAcceptingKeyword::GEO_NEAR, sub, allowedFeatures);
if (s.isOK()) {
root->add(s.getValue().release());
}
@@ -664,8 +690,8 @@ Status MatchExpressionParser::_parseSub(const char* name,
BSONElement deep = j.next();
const bool childIsTopLevel = false;
- StatusWithMatchExpression s =
- _parseSubField(sub, root, name, deep, collator, expCtx, childIsTopLevel);
+ StatusWithMatchExpression s = _parseSubField(
+ sub, root, name, deep, collator, expCtx, allowedFeatures, childIsTopLevel);
if (!s.isOK())
return s.getStatus();
@@ -885,6 +911,7 @@ StatusWithMatchExpression MatchExpressionParser::_parseElemMatch(
const BSONElement& e,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel) {
if (e.type() != Object)
return {Status(ErrorCodes::BadValue, "$elemMatch needs an Object")};
@@ -919,7 +946,7 @@ StatusWithMatchExpression MatchExpressionParser::_parseElemMatch(
// value case
AndMatchExpression theAnd;
- Status s = _parseSub("", obj, &theAnd, collator, expCtx, topLevel);
+ Status s = _parseSub("", obj, &theAnd, collator, expCtx, allowedFeatures, topLevel);
if (!s.isOK())
return s;
@@ -943,7 +970,7 @@ StatusWithMatchExpression MatchExpressionParser::_parseElemMatch(
// object case
- StatusWithMatchExpression subRaw = _parse(obj, collator, expCtx, topLevel);
+ StatusWithMatchExpression subRaw = _parse(obj, collator, expCtx, allowedFeatures, topLevel);
if (!subRaw.isOK())
return subRaw;
std::unique_ptr<MatchExpression> sub = std::move(subRaw.getValue());
@@ -968,6 +995,7 @@ StatusWithMatchExpression MatchExpressionParser::_parseAll(
const BSONElement& e,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel) {
if (e.type() != Array)
return {Status(ErrorCodes::BadValue, "$all needs an array")};
@@ -997,8 +1025,12 @@ StatusWithMatchExpression MatchExpressionParser::_parseAll(
}
const bool childIsTopLevel = false;
- StatusWithMatchExpression inner = _parseElemMatch(
- name, hopefullyElemMatchObj.firstElement(), collator, expCtx, childIsTopLevel);
+ StatusWithMatchExpression inner = _parseElemMatch(name,
+ hopefullyElemMatchObj.firstElement(),
+ collator,
+ expCtx,
+ allowedFeatures,
+ childIsTopLevel);
if (!inner.isOK())
return inner;
myAnd->add(inner.getValue().release());
@@ -1249,7 +1281,8 @@ StatusWithMatchExpression MatchExpressionParser::_parseInternalSchemaFixedArityA
StringData name,
const BSONElement& input,
const CollatorInterface* collator,
- const boost::intrusive_ptr<ExpressionContext>& expCtx) {
+ const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures) {
constexpr auto arity = T::arity();
if (input.type() != BSONType::Array) {
return {ErrorCodes::FailedToParse,
@@ -1278,7 +1311,7 @@ StatusWithMatchExpression MatchExpressionParser::_parseInternalSchemaFixedArityA
}
const bool isTopLevel = false;
- auto subexpr = _parse(elem.embeddedObject(), collator, expCtx, isTopLevel);
+ auto subexpr = _parse(elem.embeddedObject(), collator, expCtx, allowedFeatures, isTopLevel);
if (!subexpr.isOK()) {
return subexpr.getStatus();
}
@@ -1586,7 +1619,8 @@ StatusWithMatchExpression MatchExpressionParser::_parseInternalSchemaAllowedProp
StatusWithMatchExpression MatchExpressionParser::_parseGeo(const char* name,
PathAcceptingKeyword type,
- const BSONObj& section) {
+ const BSONObj& section,
+ AllowedFeatureSet allowedFeatures) {
if (PathAcceptingKeyword::WITHIN == type || PathAcceptingKeyword::GEO_INTERSECTS == type) {
std::unique_ptr<GeoExpression> gq = stdx::make_unique<GeoExpression>(name);
Status parseStatus = gq->parseFrom(section);
@@ -1602,6 +1636,12 @@ StatusWithMatchExpression MatchExpressionParser::_parseGeo(const char* name,
return {std::move(e)};
} else {
invariant(PathAcceptingKeyword::GEO_NEAR == type);
+
+ if ((allowedFeatures & AllowedFeatures::kGeoNear) == 0u) {
+ return {Status(ErrorCodes::BadValue,
+ "$geoNear, $near, and $nearSphere are not allowed in this context")};
+ }
+
std::unique_ptr<GeoNearExpression> nq = stdx::make_unique<GeoNearExpression>(name);
Status s = nq->parseFrom(section);
if (!s.isOK()) {
@@ -1633,10 +1673,16 @@ bool MatchExpressionParser::_isAggExpression(
return obj.firstElementFieldName() == kAggExpression;
}
-boost::intrusive_ptr<Expression> MatchExpressionParser::_parseAggExpression(
- BSONElement elem, const boost::intrusive_ptr<ExpressionContext>& expCtx) {
+StatusWith<boost::intrusive_ptr<Expression>> MatchExpressionParser::_parseAggExpression(
+ BSONElement elem,
+ const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures) {
invariant(expCtx);
+ if ((allowedFeatures & AllowedFeatures::kExpr) == 0u) {
+ return {Status(ErrorCodes::BadValue, "$expr is not allowed in this context")};
+ }
+
auto expr = Expression::parseOperand(
expCtx, elem.embeddedObject().firstElement(), expCtx->variablesParseState);
return expr->optimize();
diff --git a/src/mongo/db/matcher/expression_parser.h b/src/mongo/db/matcher/expression_parser.h
index 621a35e4451..75ed1a60dd7 100644
--- a/src/mongo/db/matcher/expression_parser.h
+++ b/src/mongo/db/matcher/expression_parser.h
@@ -37,6 +37,7 @@
#include "mongo/db/matcher/expression_tree.h"
#include "mongo/db/matcher/expression_type.h"
#include "mongo/db/matcher/extensions_callback.h"
+#include "mongo/db/matcher/extensions_callback_noop.h"
#include "mongo/db/pipeline/expression_context.h"
#include "mongo/stdx/functional.h"
@@ -84,6 +85,20 @@ enum class PathAcceptingKeyword {
class MatchExpressionParser {
public:
/**
+ * Features allowed in match expression parsing.
+ */
+ enum AllowedFeatures {
+ kText = 1,
+ kGeoNear = 1 << 1,
+ kJavascript = 1 << 2,
+ kExpr = 1 << 3,
+ };
+ using AllowedFeatureSet = unsigned long long;
+ static constexpr AllowedFeatureSet kBanAllSpecialFeatures = 0;
+ static constexpr AllowedFeatureSet kAllowAllSpecialFeatures =
+ std::numeric_limits<unsigned long long>::max();
+
+ /**
* Constant double representation of 2^63.
*/
static const double kLongLongMaxPlusOneAsDouble;
@@ -104,12 +119,18 @@ public:
*/
static StatusWithMatchExpression parse(
const BSONObj& obj,
- const ExtensionsCallback& extensionsCallback,
const CollatorInterface* collator,
- const boost::intrusive_ptr<ExpressionContext>& expCtx = nullptr) {
+ const boost::intrusive_ptr<ExpressionContext>& expCtx = nullptr,
+ const ExtensionsCallback& extensionsCallback = ExtensionsCallbackNoop(),
+ AllowedFeatureSet allowedFeatures = kBanAllSpecialFeatures) {
+ // A non-null ExpressionContext is required for parsing $expr.
+ if (!expCtx) {
+ invariant((allowedFeatures & AllowedFeatures::kExpr) == 0u);
+ }
+
const bool topLevelCall = true;
return MatchExpressionParser(&extensionsCallback)
- ._parse(obj, collator, expCtx, topLevelCall);
+ ._parse(obj, collator, expCtx, allowedFeatures, topLevelCall);
}
/**
@@ -171,6 +192,7 @@ private:
StatusWithMatchExpression _parse(const BSONObj& obj,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel);
/**
@@ -183,6 +205,7 @@ private:
AndMatchExpression* root,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel);
/**
@@ -196,6 +219,7 @@ private:
const BSONElement& e,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel);
StatusWithMatchExpression _parseComparison(
@@ -203,7 +227,8 @@ private:
ComparisonMatchExpression* cmp,
const BSONElement& e,
const CollatorInterface* collator,
- const boost::intrusive_ptr<ExpressionContext>& expCtx);
+ const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures);
StatusWithMatchExpression _parseMOD(const char* name,
const BSONElement& e,
@@ -231,7 +256,8 @@ private:
StatusWithMatchExpression _parseGeo(const char* name,
PathAcceptingKeyword type,
- const BSONObj& section);
+ const BSONObj& section,
+ AllowedFeatureSet allowedFeatures);
// arrays
@@ -239,12 +265,14 @@ private:
const BSONElement& e,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel);
StatusWithMatchExpression _parseAll(const char* name,
const BSONElement& e,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel);
// tree
@@ -253,12 +281,14 @@ private:
ListOfMatchExpression* out,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel);
StatusWithMatchExpression _parseNot(const char* name,
const BSONElement& e,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel);
/**
@@ -284,7 +314,8 @@ private:
StringData name,
const BSONElement& elem,
const CollatorInterface* collator,
- const boost::intrusive_ptr<ExpressionContext>& expCtx);
+ const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures);
/**
* Parses the given BSONElement into a single integer argument and creates a MatchExpression
@@ -310,8 +341,10 @@ private:
bool _isAggExpression(BSONElement elem, const boost::intrusive_ptr<ExpressionContext>& expCtx);
- boost::intrusive_ptr<Expression> _parseAggExpression(
- BSONElement elem, const boost::intrusive_ptr<ExpressionContext>& expCtx);
+ StatusWith<boost::intrusive_ptr<Expression>> _parseAggExpression(
+ BSONElement elem,
+ const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures);
StatusWithMatchExpression _parseInternalSchemaAllowedProperties(
const BSONElement& elem, const CollatorInterface* collator);
diff --git a/src/mongo/db/matcher/expression_parser_array_test.cpp b/src/mongo/db/matcher/expression_parser_array_test.cpp
index 2a9d0467ce3..23cef6b1180 100644
--- a/src/mongo/db/matcher/expression_parser_array_test.cpp
+++ b/src/mongo/db/matcher/expression_parser_array_test.cpp
@@ -38,7 +38,6 @@
#include "mongo/db/json.h"
#include "mongo/db/matcher/expression.h"
#include "mongo/db/matcher/expression_array.h"
-#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
#include "mongo/db/query/collation/collator_interface_mock.h"
namespace mongo {
@@ -48,8 +47,7 @@ using std::string;
TEST(MatchExpressionParserArrayTest, Size1) {
BSONObj query = BSON("x" << BSON("$size" << 2));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -61,8 +59,7 @@ TEST(MatchExpressionParserArrayTest, Size1) {
TEST(MatchExpressionParserArrayTest, SizeAsLong) {
BSONObj query = BSON("x" << BSON("$size" << 2LL));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -74,16 +71,14 @@ TEST(MatchExpressionParserArrayTest, SizeAsLong) {
TEST(MatchExpressionParserArrayTest, SizeAsNegativeLong) {
BSONObj query = BSON("x" << BSON("$size" << -2LL));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_FALSE(result.isOK());
}
TEST(MatchExpressionParserArrayTest, SizeTooLarge) {
BSONObj query = BSON("x" << BSON("$size" << std::numeric_limits<long long>::max()));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_FALSE(result.isOK());
}
@@ -91,16 +86,14 @@ TEST(MatchExpressionParserArrayTest, SizeAsString) {
BSONObj query = BSON("x" << BSON("$size"
<< "a"));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_FALSE(result.isOK());
}
TEST(MatchExpressionParserArrayTest, SizeWithIntegralDouble) {
BSONObj query = BSON("x" << BSON("$size" << 2.0));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -112,32 +105,28 @@ TEST(MatchExpressionParserArrayTest, SizeWithIntegralDouble) {
TEST(MatchExpressionParserArrayTest, SizeWithNegativeIntegralDouble) {
BSONObj query = BSON("x" << BSON("$size" << -2.0));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_FALSE(result.isOK());
}
TEST(MatchExpressionParserArrayTest, SizeWithDouble) {
BSONObj query = BSON("x" << BSON("$size" << 2.5));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_FALSE(result.isOK());
}
TEST(MatchExpressionParserArrayTest, SizeWithNegative) {
BSONObj query = BSON("x" << BSON("$size" << -2));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_FALSE(result.isOK());
}
TEST(MatchExpressionParserArrayTest, SizeBad) {
BSONObj query = BSON("x" << BSON("$size" << BSONNULL));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_FALSE(result.isOK());
}
@@ -146,8 +135,7 @@ TEST(MatchExpressionParserArrayTest, SizeBad) {
TEST(MatchExpressionParserArrayTest, ElemMatchArr1) {
BSONObj query = BSON("x" << BSON("$elemMatch" << BSON("x" << 1 << "y" << 2)));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -160,8 +148,7 @@ TEST(MatchExpressionParserArrayTest, ElemMatchAnd) {
BSONObj query =
BSON("x" << BSON("$elemMatch" << BSON("$and" << BSON_ARRAY(BSON("x" << 1 << "y" << 2)))));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -173,8 +160,7 @@ TEST(MatchExpressionParserArrayTest, ElemMatchAnd) {
TEST(MatchExpressionParserArrayTest, ElemMatchNor) {
BSONObj query = BSON("x" << BSON("$elemMatch" << BSON("$nor" << BSON_ARRAY(BSON("x" << 1)))));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -187,8 +173,7 @@ TEST(MatchExpressionParserArrayTest, ElemMatchOr) {
BSONObj query =
BSON("x" << BSON("$elemMatch" << BSON("$or" << BSON_ARRAY(BSON("x" << 1 << "y" << 2)))));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -200,8 +185,7 @@ TEST(MatchExpressionParserArrayTest, ElemMatchOr) {
TEST(MatchExpressionParserArrayTest, ElemMatchVal1) {
BSONObj query = BSON("x" << BSON("$elemMatch" << BSON("$gt" << 5)));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -228,8 +212,7 @@ TEST(MatchExpressionParserArrayTest, ElemMatchDBRef1) {
BSONObj query = BSON("x" << BSON("$elemMatch" << BSON("$eq" << match)));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << match)));
@@ -255,8 +238,7 @@ TEST(MatchExpressionParserArrayTest, ElemMatchDBRef2) {
BSONObj query = BSON("x" << BSON("$elemMatch" << match));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << match)));
@@ -283,8 +265,7 @@ TEST(MatchExpressionParserArrayTest, ElemMatchDBRef3) {
BSONObj query = BSON("x" << BSON("$elemMatch" << match));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << match)));
@@ -327,8 +308,7 @@ TEST(MatchExpressionParserArrayTest, ElemMatchDBRef4) {
BSONObj query = BSON("x" << BSON("$elemMatch" << matchOutOfOrder));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << match)));
@@ -358,8 +338,7 @@ TEST(MatchExpressionParserArrayTest, ElemMatchDBRef5) {
BSONObj query = BSON("x" << BSON("$elemMatch" << matchOutOfOrder));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << match)));
@@ -399,8 +378,7 @@ TEST(MatchExpressionParserArrayTest, ElemMatchDBRef6) {
BSONObj query = BSON("x" << BSON("$elemMatch" << matchMissingID));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << match)));
@@ -438,8 +416,7 @@ TEST(MatchExpressionParserArrayTest, ElemMatchDBRef7) {
BSONObj query = BSON("x" << BSON("$elemMatch" << matchMissingRef));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << match)));
@@ -483,8 +460,7 @@ TEST(MatchExpressionParserArrayTest, ElemMatchDBRef8) {
BSONObj query = BSON("x" << BSON("$elemMatch" << matchDBOnly));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << match)));
@@ -507,8 +483,7 @@ TEST(MatchExpressionParserArrayTest, ElemMatchDBRef8) {
TEST(MatchExpressionParserArrayTest, All1) {
BSONObj query = BSON("x" << BSON("$all" << BSON_ARRAY(1 << 2)));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
// Verify that the $all got parsed to AND.
@@ -525,8 +500,7 @@ TEST(MatchExpressionParserArrayTest, All1) {
TEST(MatchExpressionParserArrayTest, AllNull) {
BSONObj query = BSON("x" << BSON("$all" << BSON_ARRAY(BSONNULL)));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
// Verify that the $all got parsed to AND.
@@ -541,8 +515,7 @@ TEST(MatchExpressionParserArrayTest, AllNull) {
TEST(MatchExpressionParserArrayTest, AllBadArg) {
BSONObj query = BSON("x" << BSON("$all" << 1));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_FALSE(result.isOK());
}
@@ -556,8 +529,7 @@ TEST(MatchExpressionParserArrayTest, AllBadRegexArg) {
BSONObj query = BSON("x" << operand.obj());
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_FALSE(result.isOK());
}
@@ -571,8 +543,7 @@ TEST(MatchExpressionParserArrayTest, AllRegex1) {
BSONObj query = BSON("a" << all.obj());
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
// Verify that the $all got parsed to AND.
@@ -599,8 +570,7 @@ TEST(MatchExpressionParserArrayTest, AllRegex2) {
BSONObj query = BSON("a" << all.obj());
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
// Verify that the $all got parsed to AND.
@@ -618,8 +588,7 @@ TEST(MatchExpressionParserArrayTest, AllRegex2) {
TEST(MatchExpressionParserArrayTest, AllNonArray) {
BSONObj query = BSON("x" << BSON("$all" << BSON_ARRAY(5)));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
// Verify that the $all got parsed to AND.
@@ -636,8 +605,7 @@ TEST(MatchExpressionParserArrayTest, AllElemMatch1) {
BSONObj internal = BSON("x" << 1 << "y" << 2);
BSONObj query = BSON("x" << BSON("$all" << BSON_ARRAY(BSON("$elemMatch" << internal))));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
// Verify that the $all got parsed to an AND with a single ELEM_MATCH_OBJECT child.
@@ -658,8 +626,7 @@ TEST(MatchExpressionParserArrayTest, AllElemMatch2) {
BSONObj internal = BSON("z" << 1);
BSONObj query = BSON("x.y" << BSON("$all" << BSON_ARRAY(BSON("$elemMatch" << internal))));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
// Verify that the $all got parsed to an AND with a single ELEM_MATCH_OBJECT child.
@@ -695,8 +662,7 @@ TEST(MatchExpressionParserArrayTest, AllElemMatch2) {
TEST(MatchExpressionParserArrayTest, AllElemMatch3) {
BSONObj query = fromjson("{x: {$all: [{$elemMatch: {y: 1, z: 1}}]}}");
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
std::unique_ptr<MatchExpression> expr = std::move(result.getValue());
@@ -732,12 +698,11 @@ TEST(MatchExpressionParserArrayTest, AllElemMatchBad) {
BSONObj query = BSON("x" << BSON("$all" << BSON_ARRAY(BSON("$elemMatch" << internal) << 5)));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_FALSE(result.isOK());
query = BSON("x" << BSON("$all" << BSON_ARRAY(5 << BSON("$elemMatch" << internal))));
- result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ result = MatchExpressionParser::parse(query, collator);
ASSERT_FALSE(result.isOK());
}
@@ -746,26 +711,22 @@ TEST(MatchExpressionParserArrayTest, AllElemMatchBadMixed) {
// $elemMatch first, equality second.
BSONObj bad1 = fromjson("{x: {$all: [{$elemMatch: {y: 1}}, 3]}}");
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result1 =
- MatchExpressionParser::parse(bad1, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result1 = MatchExpressionParser::parse(bad1, collator);
ASSERT_FALSE(result1.isOK());
// equality first, $elemMatch second
BSONObj bad2 = fromjson("{x: {$all: [3, {$elemMatch: {y: 1}}]}}");
- StatusWithMatchExpression result2 =
- MatchExpressionParser::parse(bad2, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result2 = MatchExpressionParser::parse(bad2, collator);
ASSERT_FALSE(result1.isOK());
// $elemMatch first, object second
BSONObj bad3 = fromjson("{x: {$all: [{$elemMatch: {y: 1}}, {z: 1}]}}");
- StatusWithMatchExpression result3 =
- MatchExpressionParser::parse(bad3, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result3 = MatchExpressionParser::parse(bad3, collator);
ASSERT_FALSE(result3.isOK());
// object first, $elemMatch second
BSONObj bad4 = fromjson("{x: {$all: [{z: 1}, {$elemMatch: {y: 1}}]}}");
- StatusWithMatchExpression result4 =
- MatchExpressionParser::parse(bad4, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result4 = MatchExpressionParser::parse(bad4, collator);
ASSERT_FALSE(result4.isOK());
}
@@ -773,8 +734,7 @@ TEST(MatchExpressionParserArrayTest, AllElemMatchBadMixed) {
TEST(MatchExpressionParserArrayTest, AllEmptyString) {
BSONObj query = BSON("x" << BSON("$all" << BSON_ARRAY("")));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x"
@@ -799,8 +759,7 @@ TEST(MatchExpressionParserArrayTest, AllISODate) {
BSONObj query = BSON("x" << BSON("$all" << BSON_ARRAY(match)));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << notMatch)));
@@ -816,8 +775,7 @@ TEST(MatchExpressionParserArrayTest, AllISODate) {
TEST(MatchExpressionParserArrayTest, AllDottedEmptyString) {
BSONObj query = BSON("x.1" << BSON("$all" << BSON_ARRAY("")));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x"
@@ -844,8 +802,7 @@ TEST(MatchExpressionParserArrayTest, AllDottedISODate) {
BSONObj query = BSON("x.1" << BSON("$all" << BSON_ARRAY(match)));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << notMatch)));
@@ -862,8 +819,7 @@ TEST(MatchExpressionParserArrayTest, AllDottedISODate) {
TEST(MatchExpressionParserArrayTest, AllStringNullCollation) {
BSONObj query = BSON("x" << BSON("$all" << BSON_ARRAY("string")));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT_EQUALS(MatchExpression::AND, result.getValue()->matchType());
ASSERT_EQUALS(1U, result.getValue()->numChildren());
@@ -876,8 +832,7 @@ TEST(MatchExpressionParserArrayTest, AllStringNullCollation) {
TEST(MatchExpressionParserArrayTest, AllStringCollation) {
BSONObj query = BSON("x" << BSON("$all" << BSON_ARRAY("string")));
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator);
ASSERT_TRUE(result.isOK());
ASSERT_EQUALS(MatchExpression::AND, result.getValue()->matchType());
ASSERT_EQUALS(1U, result.getValue()->numChildren());
diff --git a/src/mongo/db/matcher/expression_parser_geo_test.cpp b/src/mongo/db/matcher/expression_parser_geo_test.cpp
index c7e82af29ab..b8a17a3ae2f 100644
--- a/src/mongo/db/matcher/expression_parser_geo_test.cpp
+++ b/src/mongo/db/matcher/expression_parser_geo_test.cpp
@@ -34,7 +34,7 @@
#include "mongo/db/json.h"
#include "mongo/db/matcher/expression.h"
#include "mongo/db/matcher/expression_geo.h"
-#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
+#include "mongo/db/matcher/extensions_callback_noop.h"
#include "mongo/db/pipeline/aggregation_context_fixture.h"
namespace mongo {
@@ -43,8 +43,13 @@ TEST(MatchExpressionParserGeo, WithinBox) {
BSONObj query = fromjson("{a:{$within:{$box:[{x: 4, y:4},[6,6]]}}}");
const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(fromjson("{a: [3,4]}")));
@@ -63,7 +68,11 @@ TEST(MatchExpressionParserGeo, RejectsExprAsGeometry) {
const CollatorInterface* collator = nullptr;
StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_NOT_OK(result.getStatus());
}
@@ -73,8 +82,13 @@ TEST(MatchExpressionParserGeoNear, ParseNear) {
"$geometry:{type:\"Point\", coordinates:[0,0]}}}}");
const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_TRUE(result.isOK());
MatchExpression* exp = result.getValue().get();
@@ -91,10 +105,14 @@ TEST(MatchExpressionParserGeoNear, ParseNearExtraField) {
"$geometry:{type:\"Point\", coordinates:[0,0]}}, foo: 1}}");
const CollatorInterface* collator = nullptr;
- ASSERT_THROWS(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator)
- .status_with_transitional_ignore(),
- AssertionException);
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_THROWS(MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures)
+ .status_with_transitional_ignore(),
+ AssertionException);
}
// For $near, $nearSphere, and $geoNear syntax of:
@@ -107,8 +125,13 @@ TEST(MatchExpressionParserGeoNear, ParseValidNear) {
BSONObj query = fromjson("{loc: {$near: [0,0], $maxDistance: 100, $minDistance: 50}}");
const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_TRUE(result.isOK());
MatchExpression* exp = result.getValue().get();
@@ -123,69 +146,110 @@ TEST(MatchExpressionParserGeoNear, ParseInvalidNear) {
{
BSONObj query = fromjson("{loc: {$maxDistance: 100, $near: [0,0]}}");
const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_FALSE(result.isOK());
}
{
BSONObj query = fromjson("{loc: {$minDistance: 100, $near: [0,0]}}");
const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_FALSE(result.isOK());
}
{
BSONObj query = fromjson("{loc: {$near: [0,0], $maxDistance: {}}}");
const CollatorInterface* collator = nullptr;
- ASSERT_THROWS(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator)
- .status_with_transitional_ignore(),
- AssertionException);
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_THROWS(MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures)
+ .status_with_transitional_ignore(),
+ AssertionException);
}
{
BSONObj query = fromjson("{loc: {$near: [0,0], $minDistance: {}}}");
const CollatorInterface* collator = nullptr;
- ASSERT_THROWS(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator)
- .status_with_transitional_ignore(),
- AssertionException);
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_THROWS(MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures)
+ .status_with_transitional_ignore(),
+ AssertionException);
}
{
BSONObj query = fromjson("{loc: {$near: [0,0], $eq: 40}}");
const CollatorInterface* collator = nullptr;
- ASSERT_THROWS(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator)
- .status_with_transitional_ignore(),
- AssertionException);
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_THROWS(MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures)
+ .status_with_transitional_ignore(),
+ AssertionException);
}
{
BSONObj query = fromjson("{loc: {$eq: 40, $near: [0,0]}}");
const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_FALSE(result.isOK());
}
{
BSONObj query = fromjson(
"{loc: {$near: [0,0], $geoWithin: {$geometry: {type: \"Polygon\", coordinates: []}}}}");
const CollatorInterface* collator = nullptr;
- ASSERT_THROWS(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator)
- .status_with_transitional_ignore(),
- AssertionException);
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_THROWS(MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures)
+ .status_with_transitional_ignore(),
+ AssertionException);
}
{
BSONObj query = fromjson("{loc: {$near: {$foo: 1}}}");
const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_FALSE(result.isOK());
}
{
BSONObj query = fromjson("{loc: {$minDistance: 10}}");
const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_FALSE(result.isOK());
}
}
@@ -194,8 +258,13 @@ TEST(MatchExpressionParserGeoNear, ParseValidGeoNear) {
BSONObj query = fromjson("{loc: {$geoNear: [0,0], $maxDistance: 100, $minDistance: 50}}");
const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_TRUE(result.isOK());
MatchExpression* exp = result.getValue().get();
@@ -210,40 +279,62 @@ TEST(MatchExpressionParserGeoNear, ParseInvalidGeoNear) {
{
BSONObj query = fromjson("{loc: {$maxDistance: 100, $geoNear: [0,0]}}");
const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_FALSE(result.isOK());
}
{
BSONObj query = fromjson("{loc: {$minDistance: 100, $geoNear: [0,0]}}");
const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_FALSE(result.isOK());
}
{
BSONObj query = fromjson("{loc: {$geoNear: [0,0], $eq: 1}}");
const CollatorInterface* collator = nullptr;
- ASSERT_THROWS(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator)
- .status_with_transitional_ignore(),
- AssertionException);
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_THROWS(MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures)
+ .status_with_transitional_ignore(),
+ AssertionException);
}
{
BSONObj query = fromjson("{loc: {$geoNear: [0,0], $maxDistance: {}}}");
const CollatorInterface* collator = nullptr;
- ASSERT_THROWS(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator)
- .status_with_transitional_ignore(),
- AssertionException);
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_THROWS(MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures)
+ .status_with_transitional_ignore(),
+ AssertionException);
}
{
BSONObj query = fromjson("{loc: {$geoNear: [0,0], $minDistance: {}}}");
const CollatorInterface* collator = nullptr;
- ASSERT_THROWS(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator)
- .status_with_transitional_ignore(),
- AssertionException);
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_THROWS(MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures)
+ .status_with_transitional_ignore(),
+ AssertionException);
}
}
@@ -251,8 +342,13 @@ TEST(MatchExpressionParserGeoNear, ParseValidNearSphere) {
BSONObj query = fromjson("{loc: {$nearSphere: [0,0], $maxDistance: 100, $minDistance: 50}}");
const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_TRUE(result.isOK());
MatchExpression* exp = result.getValue().get();
@@ -267,40 +363,62 @@ TEST(MatchExpressionParserGeoNear, ParseInvalidNearSphere) {
{
BSONObj query = fromjson("{loc: {$maxDistance: 100, $nearSphere: [0,0]}}");
const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_FALSE(result.isOK());
}
{
BSONObj query = fromjson("{loc: {$minDistance: 100, $nearSphere: [0,0]}}");
const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_FALSE(result.isOK());
}
{
BSONObj query = fromjson("{loc: {$nearSphere: [0,0], $maxDistance: {}}}");
const CollatorInterface* collator = nullptr;
- ASSERT_THROWS(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator)
- .status_with_transitional_ignore(),
- AssertionException);
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_THROWS(MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures)
+ .status_with_transitional_ignore(),
+ AssertionException);
}
{
BSONObj query = fromjson("{loc: {$nearSphere: [0,0], $minDistance: {}}}");
const CollatorInterface* collator = nullptr;
- ASSERT_THROWS(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator)
- .status_with_transitional_ignore(),
- AssertionException);
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_THROWS(MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures)
+ .status_with_transitional_ignore(),
+ AssertionException);
}
{
BSONObj query = fromjson("{loc: {$nearSphere: [0,0], $eq: 1}}");
const CollatorInterface* collator = nullptr;
- ASSERT_THROWS(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator)
- .status_with_transitional_ignore(),
- AssertionException);
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_THROWS(MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures)
+ .status_with_transitional_ignore(),
+ AssertionException);
}
}
diff --git a/src/mongo/db/matcher/expression_parser_leaf_test.cpp b/src/mongo/db/matcher/expression_parser_leaf_test.cpp
index 7181c8dea59..17c6efc8b4f 100644
--- a/src/mongo/db/matcher/expression_parser_leaf_test.cpp
+++ b/src/mongo/db/matcher/expression_parser_leaf_test.cpp
@@ -33,10 +33,11 @@
#include "mongo/db/matcher/expression.h"
#include "mongo/db/matcher/expression_leaf.h"
#include "mongo/db/matcher/expression_parser.h"
-#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
+#include "mongo/db/matcher/extensions_callback_noop.h"
#include "mongo/db/pipeline/expression_context_for_test.h"
#include "mongo/db/query/collation/collator_interface_mock.h"
#include "mongo/platform/decimal128.h"
+#include "mongo/unittest/death_test.h"
#include "mongo/unittest/unittest.h"
namespace mongo {
@@ -48,8 +49,7 @@ TEST(MatchExpressionParserLeafTest, NullCollation) {
BSONObj query = BSON("x"
<< "string");
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType());
EqualityMatchExpression* match = static_cast<EqualityMatchExpression*>(result.getValue().get());
@@ -61,8 +61,7 @@ TEST(MatchExpressionParserLeafTest, Collation) {
BSONObj query = BSON("x"
<< "string");
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType());
EqualityMatchExpression* match = static_cast<EqualityMatchExpression*>(result.getValue().get());
@@ -79,8 +78,11 @@ TEST(MatchExpressionParserLeafTest, ConstantExpr) {
auto varId = expCtx->variablesParseState.defineVariable("userVar");
expCtx->variables.setValue(varId, Value(123));
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), collator, expCtx);
+ auto result = MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType());
@@ -101,21 +103,30 @@ TEST(MatchExpressionParserLeafTest, ConstantExprFailsWithMissingVariable) {
BSONObj query = BSON("x" << BSON("$expr"
<< "$$userVar"));
- ASSERT_THROWS_CODE(auto sw = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), collator, expCtx),
- AssertionException,
- 17276);
+ ASSERT_THROWS_CODE(
+ auto sw = MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr),
+ AssertionException,
+ 17276);
}
-TEST(MatchExpressionParserLeafTest, ConstantExprFailsWithMissingExpressionContext) {
+DEATH_TEST(MatchExpressionParserLeafTest,
+ ConstantExprFailsWithMissingExpressionContext,
+ "Invariant failure (allowedFeatures & AllowedFeatures::kExpr) == 0u") {
boost::intrusive_ptr<ExpressionContextForTest> nullExpCtx;
const CollatorInterface* collator = nullptr;
BSONObj query = BSON("x" << BSON("$expr"
<< "$$userVar"));
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), collator, nullExpCtx);
+ auto result = MatchExpressionParser::parse(query,
+ collator,
+ nullExpCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr);
ASSERT_NOT_OK(result.getStatus());
}
@@ -123,8 +134,7 @@ TEST(MatchExpressionParserLeafTest, ConstantExprFailsWithMissingExpressionContex
TEST(MatchExpressionParserLeafTest, SimpleEQ2) {
BSONObj query = BSON("x" << BSON("$eq" << 2));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -135,8 +145,7 @@ TEST(MatchExpressionParserLeafTest, SimpleEQ2) {
TEST(MatchExpressionParserLeafTest, SimpleEQUndefined) {
BSONObj query = BSON("x" << BSON("$eq" << BSONUndefined));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
}
@@ -144,8 +153,7 @@ TEST(MatchExpressionParserLeafTest, EQNullCollation) {
BSONObj query = BSON("x" << BSON("$eq"
<< "string"));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType());
EqualityMatchExpression* match = static_cast<EqualityMatchExpression*>(result.getValue().get());
@@ -157,8 +165,7 @@ TEST(MatchExpressionParserLeafTest, EQCollation) {
BSONObj query = BSON("x" << BSON("$eq"
<< "string"));
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType());
EqualityMatchExpression* match = static_cast<EqualityMatchExpression*>(result.getValue().get());
@@ -175,8 +182,11 @@ TEST(MatchExpressionParserLeafTest, EQConstantExpr) {
auto varId = expCtx->variablesParseState.defineVariable("userVar");
expCtx->variables.setValue(varId, Value(123));
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), collator, expCtx);
+ auto result = MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType());
@@ -193,8 +203,7 @@ TEST(MatchExpressionParserLeafTest, EQConstantExpr) {
TEST(MatchExpressionParserLeafTest, SimpleGT1) {
BSONObj query = BSON("x" << BSON("$gt" << 2));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 2)));
@@ -205,8 +214,7 @@ TEST(MatchExpressionParserLeafTest, GTNullCollation) {
BSONObj query = BSON("x" << BSON("$gt"
<< "abc"));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::GT, result.getValue()->matchType());
GTMatchExpression* match = static_cast<GTMatchExpression*>(result.getValue().get());
@@ -218,8 +226,7 @@ TEST(MatchExpressionParserLeafTest, GTCollation) {
BSONObj query = BSON("x" << BSON("$gt"
<< "abc"));
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::GT, result.getValue()->matchType());
GTMatchExpression* match = static_cast<GTMatchExpression*>(result.getValue().get());
@@ -236,8 +243,11 @@ TEST(MatchExpressionParserLeafTest, GTConstantExpr) {
auto varId = expCtx->variablesParseState.defineVariable("userVar");
expCtx->variables.setValue(varId, Value(123));
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), collator, expCtx);
+ auto result = MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::GT, result.getValue()->matchType());
@@ -254,8 +264,7 @@ TEST(MatchExpressionParserLeafTest, GTConstantExpr) {
TEST(MatchExpressionParserLeafTest, SimpleLT1) {
BSONObj query = BSON("x" << BSON("$lt" << 2));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT(result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -267,8 +276,7 @@ TEST(MatchExpressionParserLeafTest, LTNullCollation) {
BSONObj query = BSON("x" << BSON("$lt"
<< "abc"));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::LT, result.getValue()->matchType());
LTMatchExpression* match = static_cast<LTMatchExpression*>(result.getValue().get());
@@ -280,8 +288,7 @@ TEST(MatchExpressionParserLeafTest, LTCollation) {
BSONObj query = BSON("x" << BSON("$lt"
<< "abc"));
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::LT, result.getValue()->matchType());
LTMatchExpression* match = static_cast<LTMatchExpression*>(result.getValue().get());
@@ -298,8 +305,11 @@ TEST(MatchExpressionParserLeafTest, LTConstantExpr) {
auto varId = expCtx->variablesParseState.defineVariable("userVar");
expCtx->variables.setValue(varId, Value(123));
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), collator, expCtx);
+ auto result = MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::LT, result.getValue()->matchType());
@@ -316,8 +326,7 @@ TEST(MatchExpressionParserLeafTest, LTConstantExpr) {
TEST(MatchExpressionParserLeafTest, SimpleGTE1) {
BSONObj query = BSON("x" << BSON("$gte" << 2));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -329,8 +338,7 @@ TEST(MatchExpressionParserLeafTest, GTENullCollation) {
BSONObj query = BSON("x" << BSON("$gte"
<< "abc"));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::GTE, result.getValue()->matchType());
GTEMatchExpression* match = static_cast<GTEMatchExpression*>(result.getValue().get());
@@ -342,8 +350,7 @@ TEST(MatchExpressionParserLeafTest, GTECollation) {
BSONObj query = BSON("x" << BSON("$gte"
<< "abc"));
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::GTE, result.getValue()->matchType());
GTEMatchExpression* match = static_cast<GTEMatchExpression*>(result.getValue().get());
@@ -360,8 +367,11 @@ TEST(MatchExpressionParserLeafTest, GTEConstantExpr) {
auto varId = expCtx->variablesParseState.defineVariable("userVar");
expCtx->variables.setValue(varId, Value(123));
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), collator, expCtx);
+ auto result = MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::GTE, result.getValue()->matchType());
@@ -380,8 +390,7 @@ TEST(MatchExpressionParserLeafTest, GTEConstantExpr) {
TEST(MatchExpressionParserLeafTest, SimpleLTE1) {
BSONObj query = BSON("x" << BSON("$lte" << 2));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT(result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -393,8 +402,7 @@ TEST(MatchExpressionParserLeafTest, LTENullCollation) {
BSONObj query = BSON("x" << BSON("$lte"
<< "abc"));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::LTE, result.getValue()->matchType());
LTEMatchExpression* match = static_cast<LTEMatchExpression*>(result.getValue().get());
@@ -406,8 +414,7 @@ TEST(MatchExpressionParserLeafTest, LTECollation) {
BSONObj query = BSON("x" << BSON("$lte"
<< "abc"));
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString);
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::LTE, result.getValue()->matchType());
LTEMatchExpression* match = static_cast<LTEMatchExpression*>(result.getValue().get());
@@ -424,8 +431,11 @@ TEST(MatchExpressionParserLeafTest, LTEConstantExpr) {
auto varId = expCtx->variablesParseState.defineVariable("userVar");
expCtx->variables.setValue(varId, Value(123));
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), collator, expCtx);
+ auto result = MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::LTE, result.getValue()->matchType());
@@ -444,8 +454,7 @@ TEST(MatchExpressionParserLeafTest, LTEConstantExpr) {
TEST(MatchExpressionParserLeafTest, SimpleNE1) {
BSONObj query = BSON("x" << BSON("$ne" << 2));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT(result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -457,8 +466,7 @@ TEST(MatchExpressionParserLeafTest, NENullCollation) {
BSONObj query = BSON("x" << BSON("$ne"
<< "string"));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::NOT, result.getValue()->matchType());
MatchExpression* child = result.getValue()->getChild(0);
@@ -472,8 +480,7 @@ TEST(MatchExpressionParserLeafTest, NECollation) {
BSONObj query = BSON("x" << BSON("$ne"
<< "string"));
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::NOT, result.getValue()->matchType());
MatchExpression* child = result.getValue()->getChild(0);
@@ -492,8 +499,11 @@ TEST(MatchExpressionParserLeafTest, NEConstantExpr) {
auto varId = expCtx->variablesParseState.defineVariable("userVar");
expCtx->variables.setValue(varId, Value(123));
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), collator, expCtx);
+ auto result = MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::NOT, result.getValue()->matchType());
@@ -510,36 +520,34 @@ TEST(MatchExpressionParserLeafTest, NEConstantExpr) {
TEST(MatchExpressionParserLeafTest, SimpleModBad1) {
BSONObj query = BSON("x" << BSON("$mod" << BSON_ARRAY(3 << 2)));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
query = BSON("x" << BSON("$mod" << BSON_ARRAY(3)));
- result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
query = BSON("x" << BSON("$mod" << BSON_ARRAY(3 << 2 << 4)));
- result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
query = BSON("x" << BSON("$mod" << BSON_ARRAY("q" << 2)));
- result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
query = BSON("x" << BSON("$mod" << 3));
- result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
query = BSON("x" << BSON("$mod" << BSON("a" << 1 << "b" << 2)));
- result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
}
TEST(MatchExpressionParserLeafTest, SimpleMod1) {
BSONObj query = BSON("x" << BSON("$mod" << BSON_ARRAY(3 << 2)));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT(result.getValue()->matchesBSON(BSON("x" << 5)));
@@ -550,8 +558,7 @@ TEST(MatchExpressionParserLeafTest, SimpleMod1) {
TEST(MatchExpressionParserLeafTest, SimpleModNotNumber) {
BSONObj query = BSON("x" << BSON("$mod" << BSON_ARRAY(2 << "r")));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT(result.getValue()->matchesBSON(BSON("x" << 2)));
@@ -571,8 +578,11 @@ TEST(MatchExpressionParserLeafTest, ModConstantExprFails) {
auto varId = expCtx->variablesParseState.defineVariable("userVar");
expCtx->variables.setValue(varId, Value(BSON_ARRAY(10 << 2)));
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), collator, expCtx);
+ auto result = MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr);
ASSERT_NOT_OK(result.getStatus());
ASSERT_EQ(result.getStatus().code(), ErrorCodes::BadValue);
}
@@ -581,8 +591,7 @@ TEST(MatchExpressionParserLeafTest, IdCollation) {
BSONObj query = BSON("$id"
<< "string");
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType());
EqualityMatchExpression* match = static_cast<EqualityMatchExpression*>(result.getValue().get());
@@ -593,8 +602,7 @@ TEST(MatchExpressionParserLeafTest, IdNullCollation) {
BSONObj query = BSON("$id"
<< "string");
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType());
EqualityMatchExpression* match = static_cast<EqualityMatchExpression*>(result.getValue().get());
@@ -611,8 +619,11 @@ TEST(MatchExpressionParserLeafTest, IdConstantExpr) {
auto varId = expCtx->variablesParseState.defineVariable("userVar");
expCtx->variables.setValue(varId, Value(123));
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), collator, expCtx);
+ auto result = MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType());
@@ -622,8 +633,7 @@ TEST(MatchExpressionParserLeafTest, RefCollation) {
BSONObj query = BSON("$ref"
<< "coll");
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType());
EqualityMatchExpression* match = static_cast<EqualityMatchExpression*>(result.getValue().get());
@@ -640,8 +650,11 @@ TEST(MatchExpressionParserLeafTest, RefConstantExpr) {
auto varId = expCtx->variablesParseState.defineVariable("userVar");
expCtx->variables.setValue(varId, Value(std::string("colName")));
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), collator, expCtx);
+ auto result = MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType());
@@ -651,8 +664,7 @@ TEST(MatchExpressionParserLeafTest, DbCollation) {
BSONObj query = BSON("$db"
<< "db");
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType());
EqualityMatchExpression* match = static_cast<EqualityMatchExpression*>(result.getValue().get());
@@ -669,8 +681,11 @@ TEST(MatchExpressionParserLeafTest, DbConstantExpr) {
auto varId = expCtx->variablesParseState.defineVariable("userVar");
expCtx->variables.setValue(varId, Value(std::string("dbName")));
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), collator, expCtx);
+ auto result = MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType());
@@ -679,8 +694,7 @@ TEST(MatchExpressionParserLeafTest, DbConstantExpr) {
TEST(MatchExpressionParserLeafTest, SimpleIN1) {
BSONObj query = BSON("x" << BSON("$in" << BSON_ARRAY(2 << 3)));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -691,8 +705,7 @@ TEST(MatchExpressionParserLeafTest, SimpleIN1) {
TEST(MatchExpressionParserLeafTest, INNullCollation) {
BSONObj query = BSON("x" << BSON("$in" << BSON_ARRAY("string")));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::MATCH_IN, result.getValue()->matchType());
InMatchExpression* match = static_cast<InMatchExpression*>(result.getValue().get());
@@ -702,8 +715,7 @@ TEST(MatchExpressionParserLeafTest, INNullCollation) {
TEST(MatchExpressionParserLeafTest, INCollation) {
BSONObj query = BSON("x" << BSON("$in" << BSON_ARRAY("string")));
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::MATCH_IN, result.getValue()->matchType());
InMatchExpression* match = static_cast<InMatchExpression*>(result.getValue().get());
@@ -720,8 +732,12 @@ TEST(MatchExpressionParserLeafTest, INConstantExprFails) {
auto varId = expCtx->variablesParseState.defineVariable("userVar");
expCtx->variables.setValue(varId, Value(BSON_ARRAY(1 << 2)));
- StatusWithMatchExpression result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), &collator, expCtx);
+ StatusWithMatchExpression result =
+ MatchExpressionParser::parse(query,
+ &collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr);
ASSERT_NOT_OK(result.getStatus());
ASSERT_EQ(result.getStatus().code(), ErrorCodes::BadValue);
@@ -731,8 +747,11 @@ TEST(MatchExpressionParserLeafTest, INConstantExprFails) {
varId = expCtx->variablesParseState.defineVariable("userVar");
expCtx->variables.setValue(varId, Value(123));
- result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), &collator, expCtx);
+ result = MatchExpressionParser::parse(query,
+ &collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr);
ASSERT_NOT_OK(result.getStatus());
ASSERT_EQ(result.getStatus().code(), ErrorCodes::BadValue);
}
@@ -746,8 +765,7 @@ TEST(MatchExpressionParserLeafTest, INSingleDBRef) {
<< "$db"
<< "db"))));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
OID oidx = OID::gen();
@@ -829,8 +847,7 @@ TEST(MatchExpressionParserLeafTest, INMultipleDBRef) {
<< "$db"
<< "db"))));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
OID oidx = OID::gen();
@@ -971,8 +988,7 @@ TEST(MatchExpressionParserLeafTest, INDBRefWithOptionalField1) {
<< "foo"
<< 12345))));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
OID oidx = OID::gen();
@@ -1007,23 +1023,22 @@ TEST(MatchExpressionParserLeafTest, INInvalidDBRefs) {
BSONObj query = BSON("x" << BSON("$in" << BSON_ARRAY(BSON("$ref"
<< "coll"))));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
- result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
+ result = MatchExpressionParser::parse(query, collator);
// second field is not $id
query = BSON("x" << BSON("$in" << BSON_ARRAY(BSON("$ref"
<< "coll"
<< "$foo"
<< 1))));
- result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
OID oid = OID::gen();
// missing $ref field
query = BSON("x" << BSON("$in" << BSON_ARRAY(BSON("$id" << oid << "foo" << 3))));
- result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
// missing $id and $ref field
@@ -1031,39 +1046,35 @@ TEST(MatchExpressionParserLeafTest, INInvalidDBRefs) {
<< "test"
<< "foo"
<< 3))));
- result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
}
TEST(MatchExpressionParserLeafTest, INExpressionDocument) {
BSONObj query = BSON("x" << BSON("$in" << BSON_ARRAY(BSON("$foo" << 1))));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
}
TEST(MatchExpressionParserLeafTest, INNotArray) {
BSONObj query = BSON("x" << BSON("$in" << 5));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
}
TEST(MatchExpressionParserLeafTest, INUndefined) {
BSONObj query = BSON("x" << BSON("$in" << BSON_ARRAY(BSONUndefined)));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
}
TEST(MatchExpressionParserLeafTest, INNotElemMatch) {
BSONObj query = BSON("x" << BSON("$in" << BSON_ARRAY(BSON("$elemMatch" << 1))));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
}
@@ -1075,8 +1086,7 @@ TEST(MatchExpressionParserLeafTest, INRegexTooLong) {
operand.appendArray("$in", inArray.obj());
BSONObj query = BSON("x" << operand.obj());
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
}
@@ -1084,8 +1094,7 @@ TEST(MatchExpressionParserLeafTest, INRegexTooLong2) {
string tooLargePattern(50 * 1000, 'z');
BSONObj query = BSON("x" << BSON("$in" << BSON_ARRAY(BSON("$regex" << tooLargePattern))));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
}
@@ -1099,8 +1108,7 @@ TEST(MatchExpressionParserLeafTest, INRegexStuff) {
BSONObj query = BSON("a" << operand.obj());
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
BSONObj matchFirst = BSON("a"
@@ -1126,8 +1134,7 @@ TEST(MatchExpressionParserLeafTest, INRegexStuff) {
TEST(MatchExpressionParserLeafTest, SimpleNIN1) {
BSONObj query = BSON("x" << BSON("$nin" << BSON_ARRAY(2 << 3)));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT(result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -1138,16 +1145,14 @@ TEST(MatchExpressionParserLeafTest, SimpleNIN1) {
TEST(MatchExpressionParserLeafTest, NINNotArray) {
BSONObj query = BSON("x" << BSON("$nin" << 5));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
}
TEST(MatchExpressionParserLeafTest, NINNullCollation) {
BSONObj query = BSON("x" << BSON("$nin" << BSON_ARRAY("string")));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::NOT, result.getValue()->matchType());
MatchExpression* child = result.getValue()->getChild(0);
@@ -1159,8 +1164,7 @@ TEST(MatchExpressionParserLeafTest, NINNullCollation) {
TEST(MatchExpressionParserLeafTest, NINCollation) {
BSONObj query = BSON("x" << BSON("$nin" << BSON_ARRAY("string")));
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator);
ASSERT_OK(result.getStatus());
ASSERT_EQUALS(MatchExpression::NOT, result.getValue()->matchType());
MatchExpression* child = result.getValue()->getChild(0);
@@ -1179,8 +1183,12 @@ TEST(MatchExpressionParserLeafTest, NINConstantExprFails) {
auto varId = expCtx->variablesParseState.defineVariable("userVar");
expCtx->variables.setValue(varId, Value(BSON_ARRAY(1 << 2)));
- StatusWithMatchExpression result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), &collator, expCtx);
+ StatusWithMatchExpression result =
+ MatchExpressionParser::parse(query,
+ &collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr);
ASSERT_NOT_OK(result.getStatus());
ASSERT_EQ(result.getStatus().code(), ErrorCodes::BadValue);
@@ -1190,8 +1198,11 @@ TEST(MatchExpressionParserLeafTest, NINConstantExprFails) {
varId = expCtx->variablesParseState.defineVariable("userVar");
expCtx->variables.setValue(varId, Value(123));
- result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), &collator, expCtx);
+ result = MatchExpressionParser::parse(query,
+ &collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr);
ASSERT_NOT_OK(result.getStatus());
ASSERT_EQ(result.getStatus().code(), ErrorCodes::BadValue);
}
@@ -1201,8 +1212,7 @@ TEST(MatchExpressionParserLeafTest, Regex1) {
b.appendRegex("x", "abc", "i");
BSONObj query = b.obj();
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT(result.getValue()->matchesBSON(BSON("x"
@@ -1219,8 +1229,7 @@ TEST(MatchExpressionParserLeafTest, Regex2) {
<< "$options"
<< "i"));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT(result.getValue()->matchesBSON(BSON("x"
@@ -1237,8 +1246,7 @@ TEST(MatchExpressionParserLeafTest, Regex3) {
<< "$regex"
<< "abc"));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT(result.getValue()->matchesBSON(BSON("x"
@@ -1256,27 +1264,26 @@ TEST(MatchExpressionParserLeafTest, RegexBad) {
<< "$optionas"
<< "i"));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
// $regex does not with numbers
query = BSON("x" << BSON("$regex" << 123));
- result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
query = BSON("x" << BSON("$regex" << BSON_ARRAY("abc")));
- result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
query = BSON("x" << BSON("$optionas"
<< "i"));
- result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
query = BSON("x" << BSON("$options"
<< "i"));
- result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
}
@@ -1284,8 +1291,7 @@ TEST(MatchExpressionParserLeafTest, RegexEmbeddedNULByte) {
BSONObj query = BSON("x" << BSON("$regex"
<< "^a\\x00b"));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
const auto value = "a\0b"_sd;
@@ -1305,8 +1311,7 @@ TEST(MatchExpressionParserLeafTest, RegexWithConstantExprFails) {
auto varId = expCtx->variablesParseState.defineVariable("userVar");
expCtx->variables.setValue(varId, Value(std::string("i")));
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
@@ -1318,7 +1323,7 @@ TEST(MatchExpressionParserLeafTest, RegexWithConstantExprFails) {
varId = expCtx->variablesParseState.defineVariable("userVar");
expCtx->variables.setValue(varId, Value(std::string("abc")));
- result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
}
@@ -1327,8 +1332,7 @@ TEST(MatchExpressionParserLeafTest, ExistsYes1) {
b.appendBool("$exists", true);
BSONObj query = BSON("x" << b.obj());
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT(result.getValue()->matchesBSON(BSON("x"
@@ -1342,8 +1346,7 @@ TEST(MatchExpressionParserLeafTest, ExistsNO1) {
b.appendBool("$exists", false);
BSONObj query = BSON("x" << b.obj());
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT(!result.getValue()->matchesBSON(BSON("x"
@@ -1355,8 +1358,7 @@ TEST(MatchExpressionParserLeafTest, ExistsNO1) {
TEST(MatchExpressionParserLeafTest, Type1) {
BSONObj query = BSON("x" << BSON("$type" << String));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT(result.getValue()->matchesBSON(BSON("x"
@@ -1367,8 +1369,7 @@ TEST(MatchExpressionParserLeafTest, Type1) {
TEST(MatchExpressionParserLeafTest, Type2) {
BSONObj query = BSON("x" << BSON("$type" << (double)NumberDouble));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT(result.getValue()->matchesBSON(BSON("x" << 5.3)));
@@ -1378,8 +1379,7 @@ TEST(MatchExpressionParserLeafTest, Type2) {
TEST(MatchExpressionParserLeafTest, TypeDoubleOperator) {
BSONObj query = BSON("x" << BSON("$type" << 1.5));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 5.3)));
@@ -1389,8 +1389,7 @@ TEST(MatchExpressionParserLeafTest, TypeDoubleOperator) {
TEST(MatchExpressionParserLeafTest, TypeDecimalOperator) {
BSONObj query = BSON("x" << BSON("$type" << mongo::NumberDecimal));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT_FALSE(result.getValue()->matchesBSON(BSON("x" << 5.3)));
@@ -1400,8 +1399,7 @@ TEST(MatchExpressionParserLeafTest, TypeDecimalOperator) {
TEST(MatchExpressionParserLeafTest, TypeNull) {
BSONObj query = BSON("x" << BSON("$type" << jstNULL));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_OK(result.getStatus());
ASSERT(!result.getValue()->matchesBSON(BSONObj()));
@@ -1416,48 +1414,35 @@ TEST(MatchExpressionParserLeafTest, TypeBadType) {
b.append("$type", (JSTypeMax + 1));
BSONObj query = BSON("x" << b.obj());
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
}
TEST(MatchExpressionParserLeafTest, TypeBad) {
BSONObj query = BSON("x" << BSON("$type" << BSON("x" << 1)));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
}
TEST(MatchExpressionParserLeafTest, TypeBadString) {
const CollatorInterface* collator = nullptr;
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$type: null}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$type: true}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$type: {}}}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
ASSERT_NOT_OK(
- MatchExpressionParser::parse(fromjson("{a: {$type: ObjectId('000000000000000000000000')}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$type: []}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ MatchExpressionParser::parse(fromjson("{a: {$type: null}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$type: true}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$type: {}}}}"), collator).getStatus());
+ ASSERT_NOT_OK(MatchExpressionParser::parse(
+ fromjson("{a: {$type: ObjectId('000000000000000000000000')}}"), collator)
.getStatus());
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$type: []}}"), collator).getStatus());
}
TEST(MatchExpressionParserLeafTest, TypeStringnameDouble) {
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression typeNumberDouble = MatchExpressionParser::parse(
- fromjson("{a: {$type: 'double'}}"), ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression typeNumberDouble =
+ MatchExpressionParser::parse(fromjson("{a: {$type: 'double'}}"), collator);
ASSERT_OK(typeNumberDouble.getStatus());
TypeMatchExpression* tmeNumberDouble =
static_cast<TypeMatchExpression*>(typeNumberDouble.getValue().get());
@@ -1468,8 +1453,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameDouble) {
TEST(MatchExpressionParserLeafTest, TypeStringNameNumberDecimal) {
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression typeNumberDecimal = MatchExpressionParser::parse(
- fromjson("{a: {$type: 'decimal'}}"), ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression typeNumberDecimal =
+ MatchExpressionParser::parse(fromjson("{a: {$type: 'decimal'}}"), collator);
ASSERT_OK(typeNumberDecimal.getStatus());
TypeMatchExpression* tmeNumberDecimal =
static_cast<TypeMatchExpression*>(typeNumberDecimal.getValue().get());
@@ -1480,8 +1465,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringNameNumberDecimal) {
TEST(MatchExpressionParserLeafTest, TypeStringnameNumberInt) {
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression typeNumberInt = MatchExpressionParser::parse(
- fromjson("{a: {$type: 'int'}}"), ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression typeNumberInt =
+ MatchExpressionParser::parse(fromjson("{a: {$type: 'int'}}"), collator);
ASSERT_OK(typeNumberInt.getStatus());
TypeMatchExpression* tmeNumberInt =
static_cast<TypeMatchExpression*>(typeNumberInt.getValue().get());
@@ -1492,8 +1477,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameNumberInt) {
TEST(MatchExpressionParserLeafTest, TypeStringnameNumberLong) {
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression typeNumberLong = MatchExpressionParser::parse(
- fromjson("{a: {$type: 'long'}}"), ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression typeNumberLong =
+ MatchExpressionParser::parse(fromjson("{a: {$type: 'long'}}"), collator);
ASSERT_OK(typeNumberLong.getStatus());
TypeMatchExpression* tmeNumberLong =
static_cast<TypeMatchExpression*>(typeNumberLong.getValue().get());
@@ -1504,8 +1489,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameNumberLong) {
TEST(MatchExpressionParserLeafTest, TypeStringnameString) {
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression typeString = MatchExpressionParser::parse(
- fromjson("{a: {$type: 'string'}}"), ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression typeString =
+ MatchExpressionParser::parse(fromjson("{a: {$type: 'string'}}"), collator);
ASSERT_OK(typeString.getStatus());
TypeMatchExpression* tmeString = static_cast<TypeMatchExpression*>(typeString.getValue().get());
ASSERT_EQ(tmeString->getBSONType(), BSONType::String);
@@ -1515,8 +1500,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameString) {
TEST(MatchExpressionParserLeafTest, TypeStringnamejstOID) {
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression typejstOID = MatchExpressionParser::parse(
- fromjson("{a: {$type: 'objectId'}}"), ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression typejstOID =
+ MatchExpressionParser::parse(fromjson("{a: {$type: 'objectId'}}"), collator);
ASSERT_OK(typejstOID.getStatus());
TypeMatchExpression* tmejstOID = static_cast<TypeMatchExpression*>(typejstOID.getValue().get());
ASSERT_EQ(tmejstOID->getBSONType(), BSONType::jstOID);
@@ -1526,8 +1511,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnamejstOID) {
TEST(MatchExpressionParserLeafTest, TypeStringnamejstNULL) {
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression typejstNULL = MatchExpressionParser::parse(
- fromjson("{a: {$type: 'null'}}"), ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression typejstNULL =
+ MatchExpressionParser::parse(fromjson("{a: {$type: 'null'}}"), collator);
ASSERT_OK(typejstNULL.getStatus());
TypeMatchExpression* tmejstNULL =
static_cast<TypeMatchExpression*>(typejstNULL.getValue().get());
@@ -1538,8 +1523,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnamejstNULL) {
TEST(MatchExpressionParserLeafTest, TypeStringnameBool) {
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression typeBool = MatchExpressionParser::parse(
- fromjson("{a: {$type: 'bool'}}"), ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression typeBool =
+ MatchExpressionParser::parse(fromjson("{a: {$type: 'bool'}}"), collator);
ASSERT_OK(typeBool.getStatus());
TypeMatchExpression* tmeBool = static_cast<TypeMatchExpression*>(typeBool.getValue().get());
ASSERT_EQ(tmeBool->getBSONType(), BSONType::Bool);
@@ -1549,8 +1534,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameBool) {
TEST(MatchExpressionParserLeafTest, TypeStringnameObject) {
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression typeObject = MatchExpressionParser::parse(
- fromjson("{a: {$type: 'object'}}"), ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression typeObject =
+ MatchExpressionParser::parse(fromjson("{a: {$type: 'object'}}"), collator);
ASSERT_OK(typeObject.getStatus());
TypeMatchExpression* tmeObject = static_cast<TypeMatchExpression*>(typeObject.getValue().get());
ASSERT_EQ(tmeObject->getBSONType(), BSONType::Object);
@@ -1560,8 +1545,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameObject) {
TEST(MatchExpressionParserLeafTest, TypeStringnameArray) {
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression typeArray = MatchExpressionParser::parse(
- fromjson("{a: {$type: 'array'}}"), ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression typeArray =
+ MatchExpressionParser::parse(fromjson("{a: {$type: 'array'}}"), collator);
ASSERT_OK(typeArray.getStatus());
TypeMatchExpression* tmeArray = static_cast<TypeMatchExpression*>(typeArray.getValue().get());
ASSERT_EQ(tmeArray->getBSONType(), BSONType::Array);
@@ -1571,8 +1556,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameArray) {
TEST(MatchExpressionParserLeafTest, TypeStringnameNumber) {
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression typeNumber = MatchExpressionParser::parse(
- fromjson("{a: {$type: 'number'}}"), ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression typeNumber =
+ MatchExpressionParser::parse(fromjson("{a: {$type: 'number'}}"), collator);
ASSERT_OK(typeNumber.getStatus());
TypeMatchExpression* tmeNumber = static_cast<TypeMatchExpression*>(typeNumber.getValue().get());
ASSERT_TRUE(tmeNumber->matchesBSON(fromjson("{a: 5.4}")));
@@ -1583,22 +1568,22 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameNumber) {
TEST(MatchExpressionParserLeafTest, InvalidTypeCodeLessThanMinKeyFailsToParse) {
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression typeNumber = MatchExpressionParser::parse(
- fromjson("{a: {$type: -20}}"), ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression typeNumber =
+ MatchExpressionParser::parse(fromjson("{a: {$type: -20}}"), collator);
ASSERT_NOT_OK(typeNumber.getStatus());
}
TEST(MatchExpressionParserLeafTest, InvalidTypeCodeGreaterThanMaxKeyFailsToParse) {
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression typeNumber = MatchExpressionParser::parse(
- fromjson("{a: {$type: 400}}"), ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression typeNumber =
+ MatchExpressionParser::parse(fromjson("{a: {$type: 400}}"), collator);
ASSERT_NOT_OK(typeNumber.getStatus());
}
TEST(MatchExpressionParserLeafTest, InvalidTypeCodeUnusedBetweenMinAndMaxFailsToParse) {
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression typeNumber = MatchExpressionParser::parse(
- fromjson("{a: {$type: 62}}"), ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression typeNumber =
+ MatchExpressionParser::parse(fromjson("{a: {$type: 62}}"), collator);
ASSERT_NOT_OK(typeNumber.getStatus());
}
@@ -1611,8 +1596,7 @@ TEST(MatchExpressionParserLeafTest, ValidTypeCodesParseSuccessfully) {
for (auto type : validTypes) {
BSONObj predicate = BSON("a" << BSON("$type" << type));
const CollatorInterface* collator = nullptr;
- auto expression = MatchExpressionParser::parse(
- predicate, ExtensionsCallbackDisallowExtensions(), collator);
+ auto expression = MatchExpressionParser::parse(predicate, collator);
ASSERT_OK(expression.getStatus());
auto typeExpression = static_cast<TypeMatchExpression*>(expression.getValue().get());
ASSERT_EQ(type, typeExpression->getBSONType());
@@ -1628,8 +1612,7 @@ TEST(MatchExpressionParserLeafTest, TypeWithConstantExprFails) {
auto varId = expCtx->variablesParseState.defineVariable("userVar");
expCtx->variables.setValue(varId, Value(static_cast<int>(BSONType::NumberDouble)));
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_NOT_OK(result.getStatus());
}
@@ -1637,77 +1620,55 @@ TEST(MatchExpressionParserTest, BitTestMatchExpressionValidMask) {
const double k2Power53 = scalbn(1, 32);
const CollatorInterface* collator = nullptr;
- ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << 54)),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_OK(MatchExpressionParser::parse(
- BSON("a" << BSON("$bitsAllSet" << std::numeric_limits<long long>::max())),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << k2Power53)),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << k2Power53 - 1)),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_OK(
+ MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << 54)), collator).getStatus());
+ ASSERT_OK(
+ MatchExpressionParser::parse(
+ BSON("a" << BSON("$bitsAllSet" << std::numeric_limits<long long>::max())), collator)
+ .getStatus());
+ ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << k2Power53)), collator)
.getStatus());
+ ASSERT_OK(
+ MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << k2Power53 - 1)), collator)
+ .getStatus());
- ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << 54)),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_OK(MatchExpressionParser::parse(
- BSON("a" << BSON("$bitsAllClear" << std::numeric_limits<long long>::max())),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << k2Power53)),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << k2Power53 - 1)),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << 54)), collator)
.getStatus());
+ ASSERT_OK(
+ MatchExpressionParser::parse(
+ BSON("a" << BSON("$bitsAllClear" << std::numeric_limits<long long>::max())), collator)
+ .getStatus());
+ ASSERT_OK(
+ MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << k2Power53)), collator)
+ .getStatus());
+ ASSERT_OK(
+ MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << k2Power53 - 1)), collator)
+ .getStatus());
- ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << 54)),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_OK(MatchExpressionParser::parse(
- BSON("a" << BSON("$bitsAnySet" << std::numeric_limits<long long>::max())),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << k2Power53)),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << k2Power53 - 1)),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_OK(
+ MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << 54)), collator).getStatus());
+ ASSERT_OK(
+ MatchExpressionParser::parse(
+ BSON("a" << BSON("$bitsAnySet" << std::numeric_limits<long long>::max())), collator)
+ .getStatus());
+ ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << k2Power53)), collator)
.getStatus());
+ ASSERT_OK(
+ MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << k2Power53 - 1)), collator)
+ .getStatus());
- ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << 54)),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_OK(MatchExpressionParser::parse(
- BSON("a" << BSON("$bitsAnyClear" << std::numeric_limits<long long>::max())),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << k2Power53)),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << k2Power53 - 1)),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << 54)), collator)
.getStatus());
+ ASSERT_OK(
+ MatchExpressionParser::parse(
+ BSON("a" << BSON("$bitsAnyClear" << std::numeric_limits<long long>::max())), collator)
+ .getStatus());
+ ASSERT_OK(
+ MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << k2Power53)), collator)
+ .getStatus());
+ ASSERT_OK(
+ MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << k2Power53 - 1)), collator)
+ .getStatus());
}
TEST(MatchExpressionParserTest, BitTestMatchExpressionValidArray) {
@@ -1718,79 +1679,59 @@ TEST(MatchExpressionParserTest, BitTestMatchExpressionValidArray) {
ASSERT_EQ(BSONType::NumberLong, bsonArrayLongLong[3].type());
const CollatorInterface* collator = nullptr;
- ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << BSON_ARRAY(0))),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
+ ASSERT_OK(
+ MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << BSON_ARRAY(0))), collator)
+ .getStatus());
ASSERT_OK(MatchExpressionParser::parse(
- BSON("a" << BSON("$bitsAllSet" << BSON_ARRAY(0 << 1 << 2 << 3))),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ BSON("a" << BSON("$bitsAllSet" << BSON_ARRAY(0 << 1 << 2 << 3))), collator)
.getStatus());
ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << bsonArrayLongLong)),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
ASSERT_OK(MatchExpressionParser::parse(
BSON("a" << BSON("$bitsAllSet" << BSON_ARRAY(std::numeric_limits<int>::max()))),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
- ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << BSON_ARRAY(0))),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
+ ASSERT_OK(
+ MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << BSON_ARRAY(0))), collator)
+ .getStatus());
ASSERT_OK(MatchExpressionParser::parse(
- BSON("a" << BSON("$bitsAllClear" << BSON_ARRAY(0 << 1 << 2 << 3))),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ BSON("a" << BSON("$bitsAllClear" << BSON_ARRAY(0 << 1 << 2 << 3))), collator)
.getStatus());
ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << bsonArrayLongLong)),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
ASSERT_OK(MatchExpressionParser::parse(
BSON("a" << BSON("$bitsAllClear" << BSON_ARRAY(std::numeric_limits<int>::max()))),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
- ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << BSON_ARRAY(0))),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
+ ASSERT_OK(
+ MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << BSON_ARRAY(0))), collator)
+ .getStatus());
ASSERT_OK(MatchExpressionParser::parse(
- BSON("a" << BSON("$bitsAnySet" << BSON_ARRAY(0 << 1 << 2 << 3))),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ BSON("a" << BSON("$bitsAnySet" << BSON_ARRAY(0 << 1 << 2 << 3))), collator)
.getStatus());
ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << bsonArrayLongLong)),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
ASSERT_OK(MatchExpressionParser::parse(
BSON("a" << BSON("$bitsAnySet" << BSON_ARRAY(std::numeric_limits<int>::max()))),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
- ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << BSON_ARRAY(0))),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
+ ASSERT_OK(
+ MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << BSON_ARRAY(0))), collator)
+ .getStatus());
ASSERT_OK(MatchExpressionParser::parse(
- BSON("a" << BSON("$bitsAnyClear" << BSON_ARRAY(0 << 1 << 2 << 3))),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ BSON("a" << BSON("$bitsAnyClear" << BSON_ARRAY(0 << 1 << 2 << 3))), collator)
.getStatus());
ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << bsonArrayLongLong)),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
ASSERT_OK(MatchExpressionParser::parse(
BSON("a" << BSON("$bitsAnyClear" << BSON_ARRAY(std::numeric_limits<int>::max()))),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
}
@@ -1800,7 +1741,6 @@ TEST(MatchExpressionParserTest, BitTestMatchExpressionValidBinData) {
ASSERT_OK(
MatchExpressionParser::parse(
fromjson("{a: {$bitsAllSet: {$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}}}"),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
@@ -1808,14 +1748,12 @@ TEST(MatchExpressionParserTest, BitTestMatchExpressionValidBinData) {
MatchExpressionParser::parse(
fromjson(
"{a: {$bitsAllClear: {$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}}}"),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
ASSERT_OK(
MatchExpressionParser::parse(
fromjson("{a: {$bitsAnySet: {$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}}}"),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
@@ -1823,496 +1761,308 @@ TEST(MatchExpressionParserTest, BitTestMatchExpressionValidBinData) {
MatchExpressionParser::parse(
fromjson(
"{a: {$bitsAnyClear: {$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}}}"),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
}
TEST(MatchExpressionParserTest, BitTestMatchExpressionInvalidMaskType) {
const CollatorInterface* collator = nullptr;
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: null}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: true}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: {}}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: ''}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: null}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: true}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: {}}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: ''}}"), collator).getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: null}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: true}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: {}}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: ''}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(
- fromjson("{a: {$bitsAllClear: ObjectId('000000000000000000000000')}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: null}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: true}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: {}}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: ''}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(
+ fromjson("{a: {$bitsAllClear: ObjectId('000000000000000000000000')}}"), collator)
+ .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: null}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: true}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: {}}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: ''}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(
- fromjson("{a: {$bitsAnySet: ObjectId('000000000000000000000000')}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: null}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: true}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: {}}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: ''}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(
+ fromjson("{a: {$bitsAnySet: ObjectId('000000000000000000000000')}}"), collator)
+ .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: null}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: true}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: {}}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: ''}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(
- fromjson("{a: {$bitsAnyClear: ObjectId('000000000000000000000000')}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: null}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: true}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: {}}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: ''}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(
+ fromjson("{a: {$bitsAnyClear: ObjectId('000000000000000000000000')}}"), collator)
+ .getStatus());
}
TEST(MatchExpressionParserTest, BitTestMatchExpressionInvalidMaskValue) {
const double kLongLongMaxAsDouble = scalbn(1, std::numeric_limits<long long>::digits);
const CollatorInterface* collator = nullptr;
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: NaN}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: -54}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(
- BSON("a" << BSON("$bitsAllSet" << std::numeric_limits<double>::max())),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
ASSERT_NOT_OK(
- MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << kLongLongMaxAsDouble)),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: NaN}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: -54}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(
+ BSON("a" << BSON("$bitsAllSet" << std::numeric_limits<double>::max())), collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: 2.5}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(
+ BSON("a" << BSON("$bitsAllSet" << kLongLongMaxAsDouble)), collator)
.getStatus());
-
ASSERT_NOT_OK(
- MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << Decimal128("2.5"))),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: 2.5}}"), collator).getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: NaN}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: -54}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
ASSERT_NOT_OK(MatchExpressionParser::parse(
- BSON("a" << BSON("$bitsAllClear" << std::numeric_limits<double>::max())),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ BSON("a" << BSON("$bitsAllSet" << Decimal128("2.5"))), collator)
.getStatus());
+
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: NaN}}"), collator).getStatus());
ASSERT_NOT_OK(
- MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << kLongLongMaxAsDouble)),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: -54}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(
+ BSON("a" << BSON("$bitsAllClear" << std::numeric_limits<double>::max())), collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: 2.5}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(
+ BSON("a" << BSON("$bitsAllClear" << kLongLongMaxAsDouble)), collator)
.getStatus());
-
ASSERT_NOT_OK(
- MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << Decimal128("2.5"))),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: 2.5}}"), collator).getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: NaN}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: -54}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
ASSERT_NOT_OK(MatchExpressionParser::parse(
- BSON("a" << BSON("$bitsAnySet" << std::numeric_limits<double>::max())),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ BSON("a" << BSON("$bitsAllClear" << Decimal128("2.5"))), collator)
.getStatus());
+
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: NaN}}"), collator).getStatus());
ASSERT_NOT_OK(
- MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << kLongLongMaxAsDouble)),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: -54}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(
+ BSON("a" << BSON("$bitsAnySet" << std::numeric_limits<double>::max())), collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: 2.5}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(
+ BSON("a" << BSON("$bitsAnySet" << kLongLongMaxAsDouble)), collator)
.getStatus());
-
ASSERT_NOT_OK(
- MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << Decimal128("2.5"))),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: 2.5}}"), collator).getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: NaN}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: -54}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
ASSERT_NOT_OK(MatchExpressionParser::parse(
- BSON("a" << BSON("$bitsAnyClear" << std::numeric_limits<double>::max())),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ BSON("a" << BSON("$bitsAnySet" << Decimal128("2.5"))), collator)
.getStatus());
+
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: NaN}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: -54}}"), collator).getStatus());
ASSERT_NOT_OK(
- MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << kLongLongMaxAsDouble)),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ MatchExpressionParser::parse(
+ BSON("a" << BSON("$bitsAnyClear" << std::numeric_limits<double>::max())), collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: 2.5}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(
+ BSON("a" << BSON("$bitsAnyClear" << kLongLongMaxAsDouble)), collator)
.getStatus());
-
ASSERT_NOT_OK(
- MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << Decimal128("2.5"))),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: 2.5}}"), collator).getStatus());
+
+ ASSERT_NOT_OK(MatchExpressionParser::parse(
+ BSON("a" << BSON("$bitsAnyClear" << Decimal128("2.5"))), collator)
+ .getStatus());
}
TEST(MatchExpressionParserTest, BitTestMatchExpressionInvalidArray) {
const CollatorInterface* collator = nullptr;
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [null]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [true]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: ['']}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [{}]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [[]]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [-1]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [2.5]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [null]}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [true]}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: ['']}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [{}]}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [[]]}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [-1]}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [2.5]}}"), collator).getStatus());
ASSERT_NOT_OK(
MatchExpressionParser::parse(
fromjson(
"{a: {$bitsAllSet: [{$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}]}}"),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [null]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [true]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: ['']}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [{}]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [[]]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [null]}}"), collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [-1]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [true]}}"), collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [2.5]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: ['']}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [{}]}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [[]]}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [-1]}}"), collator).getStatus());
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [2.5]}}"), collator)
.getStatus());
ASSERT_NOT_OK(
MatchExpressionParser::parse(
fromjson(
"{a: {$bitsAllClear: [{$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}]}}"),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [null]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [true]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: ['']}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [{}]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [[]]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [-1]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [2.5]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [null]}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [true]}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: ['']}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [{}]}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [[]]}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [-1]}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [2.5]}}"), collator).getStatus());
ASSERT_NOT_OK(
MatchExpressionParser::parse(
fromjson(
"{a: {$bitsAnySet: [{$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}]}}"),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [null]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [true]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [null]}}"), collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: ['']}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [true]}}"), collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [{}]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [[]]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [-1]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [2.5]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: ['']}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [{}]}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [[]]}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [-1]}}"), collator).getStatus());
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [2.5]}}"), collator)
.getStatus());
ASSERT_NOT_OK(
MatchExpressionParser::parse(
fromjson(
"{a: {$bitsAnyClear: [{$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}]}}"),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
}
TEST(MatchExpressionParserTest, BitTestMatchExpressionInvalidArrayValue) {
const CollatorInterface* collator = nullptr;
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [-54]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [NaN]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [2.5]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [1e100]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [-54]}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [NaN]}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [2.5]}}"), collator).getStatus());
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [1e100]}}"), collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [-1e100]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [-1e100]}}"), collator)
.getStatus());
ASSERT_NOT_OK(
MatchExpressionParser::parse(
BSON("a" << BSON("$bitsAllSet" << BSON_ARRAY(std::numeric_limits<long long>::max()))),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
ASSERT_NOT_OK(
MatchExpressionParser::parse(
BSON("a" << BSON("$bitsAllSet" << BSON_ARRAY(std::numeric_limits<long long>::min()))),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [-54]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [-54]}}"), collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [NaN]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [NaN]}}"), collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [2.5]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [2.5]}}"), collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [1e100]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [1e100]}}"), collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [-1e100]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [-1e100]}}"), collator)
.getStatus());
ASSERT_NOT_OK(
MatchExpressionParser::parse(
BSON("a" << BSON("$bitsAllClear" << BSON_ARRAY(std::numeric_limits<long long>::max()))),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
ASSERT_NOT_OK(
MatchExpressionParser::parse(
BSON("a" << BSON("$bitsAllClear" << BSON_ARRAY(std::numeric_limits<long long>::min()))),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [-54]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [NaN]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [2.5]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
- .getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [1e100]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [-54]}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [NaN]}}"), collator).getStatus());
+ ASSERT_NOT_OK(
+ MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [2.5]}}"), collator).getStatus());
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [1e100]}}"), collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [-1e100]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [-1e100]}}"), collator)
.getStatus());
ASSERT_NOT_OK(
MatchExpressionParser::parse(
BSON("a" << BSON("$bitsAnySet" << BSON_ARRAY(std::numeric_limits<long long>::max()))),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
ASSERT_NOT_OK(
MatchExpressionParser::parse(
BSON("a" << BSON("$bitsAnySet" << BSON_ARRAY(std::numeric_limits<long long>::min()))),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [-54]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [-54]}}"), collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [NaN]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [NaN]}}"), collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [2.5]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [2.5]}}"), collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [1e100]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [1e100]}}"), collator)
.getStatus());
- ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [-1e100]}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator)
+ ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [-1e100]}}"), collator)
.getStatus());
ASSERT_NOT_OK(
MatchExpressionParser::parse(
BSON("a" << BSON("$bitsAnyClear" << BSON_ARRAY(std::numeric_limits<long long>::max()))),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
ASSERT_NOT_OK(
MatchExpressionParser::parse(
BSON("a" << BSON("$bitsAnyClear" << BSON_ARRAY(std::numeric_limits<long long>::min()))),
- ExtensionsCallbackDisallowExtensions(),
collator)
.getStatus());
}
@@ -2325,27 +2075,31 @@ TEST(MatchExpressionParserLeafTest, BitTestWithConstantExprFails) {
expCtx->variables.setValue(varId, Value(BSON_ARRAY(1 << 5)));
ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [{$expr: 'userVar'}]}}"),
- ExtensionsCallbackDisallowExtensions(),
collator,
- expCtx)
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr)
.getStatus());
ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: {$expr: 'userVar'}}}"),
- ExtensionsCallbackDisallowExtensions(),
collator,
- expCtx)
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr)
.getStatus());
ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: {$expr: 'userVar'}}}"),
- ExtensionsCallbackDisallowExtensions(),
collator,
- expCtx)
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr)
.getStatus());
ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: {$expr: 'userVar'}}}"),
- ExtensionsCallbackDisallowExtensions(),
collator,
- expCtx)
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr)
.getStatus());
}
} // namespace mongo
diff --git a/src/mongo/db/matcher/expression_parser_test.cpp b/src/mongo/db/matcher/expression_parser_test.cpp
index 9026782ffdb..9f0276b7028 100644
--- a/src/mongo/db/matcher/expression_parser_test.cpp
+++ b/src/mongo/db/matcher/expression_parser_test.cpp
@@ -36,15 +36,15 @@
#include "mongo/db/json.h"
#include "mongo/db/matcher/expression.h"
#include "mongo/db/matcher/expression_leaf.h"
-#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
+#include "mongo/db/matcher/extensions_callback_noop.h"
+#include "mongo/db/pipeline/expression_context_for_test.h"
namespace mongo {
TEST(MatchExpressionParserTest, SimpleEQ1) {
BSONObj query = BSON("x" << 2);
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(result.getValue()->matchesBSON(BSON("x" << 2)));
@@ -54,8 +54,7 @@ TEST(MatchExpressionParserTest, SimpleEQ1) {
TEST(MatchExpressionParserTest, Multiple1) {
BSONObj query = BSON("x" << 5 << "y" << BSON("$gt" << 5 << "$lt" << 8));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(result.getValue()->matchesBSON(BSON("x" << 5 << "y" << 7)));
@@ -68,24 +67,22 @@ TEST(MatchExpressionParserTest, Multiple1) {
TEST(AtomicMatchExpressionTest, AtomicOperator1) {
BSONObj query = BSON("x" << 5 << "$atomic" << BSON("$gt" << 5 << "$lt" << 8));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
query = BSON("x" << 5 << "$isolated" << 1);
- result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
query = BSON("x" << 5 << "y" << BSON("$isolated" << 1));
- result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ result = MatchExpressionParser::parse(query, collator);
ASSERT_FALSE(result.isOK());
}
TEST(MatchExpressionParserTest, MinDistanceWithoutNearFailsToParse) {
BSONObj query = fromjson("{loc: {$minDistance: 10}}");
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_FALSE(result.isOK());
}
@@ -229,31 +226,26 @@ TEST(StatusWithTest, Fib1) {
TEST(MatchExpressionParserTest, AlwaysFalseFailsToParseNonOneArguments) {
auto queryIntArgument = BSON("$alwaysFalse" << 0);
- auto expr = MatchExpressionParser::parse(
- queryIntArgument, ExtensionsCallbackDisallowExtensions(), nullptr);
+ auto expr = MatchExpressionParser::parse(queryIntArgument, nullptr);
ASSERT_EQ(expr.getStatus(), ErrorCodes::FailedToParse);
auto queryStringArgument = BSON("$alwaysFalse"
<< "");
- expr = MatchExpressionParser::parse(
- queryStringArgument, ExtensionsCallbackDisallowExtensions(), nullptr);
+ expr = MatchExpressionParser::parse(queryStringArgument, nullptr);
ASSERT_EQ(expr.getStatus(), ErrorCodes::FailedToParse);
auto queryDoubleArgument = BSON("$alwaysFalse" << 1.1);
- expr = MatchExpressionParser::parse(
- queryDoubleArgument, ExtensionsCallbackDisallowExtensions(), nullptr);
+ expr = MatchExpressionParser::parse(queryDoubleArgument, nullptr);
ASSERT_EQ(expr.getStatus(), ErrorCodes::FailedToParse);
auto queryFalseArgument = BSON("$alwaysFalse" << true);
- expr = MatchExpressionParser::parse(
- queryFalseArgument, ExtensionsCallbackDisallowExtensions(), nullptr);
+ expr = MatchExpressionParser::parse(queryFalseArgument, nullptr);
ASSERT_EQ(expr.getStatus(), ErrorCodes::FailedToParse);
}
TEST(MatchExpressionParserTest, AlwaysFalseParsesIntegerArgument) {
auto query = BSON("$alwaysFalse" << 1);
- auto expr =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), nullptr);
+ auto expr = MatchExpressionParser::parse(query, nullptr);
ASSERT_OK(expr.getStatus());
ASSERT_FALSE(expr.getValue()->matchesBSON(fromjson("{}")));
@@ -263,35 +255,138 @@ TEST(MatchExpressionParserTest, AlwaysFalseParsesIntegerArgument) {
TEST(MatchExpressionParserTest, AlwaysTrueFailsToParseNonOneArguments) {
auto queryIntArgument = BSON("$alwaysTrue" << 0);
- auto expr = MatchExpressionParser::parse(
- queryIntArgument, ExtensionsCallbackDisallowExtensions(), nullptr);
+ auto expr = MatchExpressionParser::parse(queryIntArgument, nullptr);
ASSERT_EQ(expr.getStatus(), ErrorCodes::FailedToParse);
auto queryStringArgument = BSON("$alwaysTrue"
<< "");
- expr = MatchExpressionParser::parse(
- queryStringArgument, ExtensionsCallbackDisallowExtensions(), nullptr);
+ expr = MatchExpressionParser::parse(queryStringArgument, nullptr);
ASSERT_EQ(expr.getStatus(), ErrorCodes::FailedToParse);
auto queryDoubleArgument = BSON("$alwaysTrue" << 1.1);
- expr = MatchExpressionParser::parse(
- queryDoubleArgument, ExtensionsCallbackDisallowExtensions(), nullptr);
+ expr = MatchExpressionParser::parse(queryDoubleArgument, nullptr);
ASSERT_EQ(expr.getStatus(), ErrorCodes::FailedToParse);
auto queryFalseArgument = BSON("$alwaysTrue" << true);
- expr = MatchExpressionParser::parse(
- queryFalseArgument, ExtensionsCallbackDisallowExtensions(), nullptr);
+ expr = MatchExpressionParser::parse(queryFalseArgument, nullptr);
ASSERT_EQ(expr.getStatus(), ErrorCodes::FailedToParse);
}
TEST(MatchExpressionParserTest, AlwaysTrueParsesIntegerArgument) {
auto query = BSON("$alwaysTrue" << 1);
- auto expr =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), nullptr);
+ auto expr = MatchExpressionParser::parse(query, nullptr);
ASSERT_OK(expr.getStatus());
ASSERT_TRUE(expr.getValue()->matchesBSON(fromjson("{}")));
ASSERT_TRUE(expr.getValue()->matchesBSON(fromjson("{x: 1}")));
ASSERT_TRUE(expr.getValue()->matchesBSON(fromjson("{x: 'blah'}")));
}
+
+TEST(MatchExpressionParserTest, TextFailsToParseWhenDisallowed) {
+ auto query = fromjson("{$text: {$search: 'str'}}");
+ const CollatorInterface* collator = nullptr;
+ ASSERT_NOT_OK(MatchExpressionParser::parse(query, collator).getStatus());
+}
+
+TEST(MatchExpressionParserTest, TextParsesSuccessfullyWhenAllowed) {
+ auto query = fromjson("{$text: {$search: 'str'}}");
+ const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_OK(MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kText)
+ .getStatus());
+}
+
+TEST(MatchExpressionParserTest, WhereFailsToParseWhenDisallowed) {
+ auto query = fromjson("{$where: 'this.a == this.b'}");
+ const CollatorInterface* collator = nullptr;
+ ASSERT_NOT_OK(MatchExpressionParser::parse(query, collator).getStatus());
+}
+
+TEST(MatchExpressionParserTest, WhereParsesSuccessfullyWhenAllowed) {
+ auto query = fromjson("{$where: 'this.a == this.b'}");
+ const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_OK(MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kJavascript)
+ .getStatus());
+}
+
+TEST(MatchExpressionParserTest, NearSphereFailsToParseWhenDisallowed) {
+ auto query = fromjson("{a: {$nearSphere: {$geometry: {type: 'Point', coordinates: [0, 0]}}}}");
+ const CollatorInterface* collator = nullptr;
+ ASSERT_NOT_OK(MatchExpressionParser::parse(query, collator).getStatus());
+}
+
+TEST(MatchExpressionParserTest, NearSphereParsesSuccessfullyWhenAllowed) {
+ auto query = fromjson("{a: {$nearSphere: {$geometry: {type: 'Point', coordinates: [0, 0]}}}}");
+ const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_OK(MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kGeoNear)
+ .getStatus());
+}
+
+TEST(MatchExpressionParserTest, GeoNearFailsToParseWhenDisallowed) {
+ auto query = fromjson("{a: {$geoNear: {$geometry: {type: 'Point', coordinates: [0, 0]}}}}");
+ const CollatorInterface* collator = nullptr;
+ ASSERT_NOT_OK(MatchExpressionParser::parse(query, collator).getStatus());
+}
+
+TEST(MatchExpressionParserTest, GeoNearParsesSuccessfullyWhenAllowed) {
+ auto query = fromjson("{a: {$geoNear: {$geometry: {type: 'Point', coordinates: [0, 0]}}}}");
+ const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_OK(MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kGeoNear)
+ .getStatus());
+}
+
+TEST(MatchExpressionParserTest, NearFailsToParseWhenDisallowed) {
+ auto query = fromjson("{a: {$near: {$geometry: {type: 'Point', coordinates: [0, 0]}}}}");
+ const CollatorInterface* collator = nullptr;
+ ASSERT_NOT_OK(MatchExpressionParser::parse(query, collator).getStatus());
+}
+
+TEST(MatchExpressionParserTest, NearParsesSuccessfullyWhenAllowed) {
+ auto query = fromjson("{a: {$near: {$geometry: {type: 'Point', coordinates: [0, 0]}}}}");
+ const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_OK(MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kGeoNear)
+ .getStatus());
+}
+
+TEST(MatchExpressionParserTest, ExprFailsToParseWhenDisallowed) {
+ auto query = fromjson("{a: {$expr: 5}}");
+ const CollatorInterface* collator = nullptr;
+ ASSERT_NOT_OK(MatchExpressionParser::parse(query, collator).getStatus());
+}
+
+TEST(MatchExpressionParserTest, ExprParsesSuccessfullyWhenAllowed) {
+ auto query = fromjson("{a: {$expr: 5}}");
+ const CollatorInterface* collator = nullptr;
+ const boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ ASSERT_OK(MatchExpressionParser::parse(query,
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatures::kExpr)
+ .getStatus());
+}
}
diff --git a/src/mongo/db/matcher/expression_parser_tree.cpp b/src/mongo/db/matcher/expression_parser_tree.cpp
index b7ba5964253..1e4290fcdc9 100644
--- a/src/mongo/db/matcher/expression_parser_tree.cpp
+++ b/src/mongo/db/matcher/expression_parser_tree.cpp
@@ -43,6 +43,7 @@ Status MatchExpressionParser::_parseTreeList(const BSONObj& arr,
ListOfMatchExpression* out,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel) {
if (arr.isEmpty())
return Status(ErrorCodes::BadValue, "$and/$or/$nor must be a nonempty array");
@@ -54,7 +55,8 @@ Status MatchExpressionParser::_parseTreeList(const BSONObj& arr,
if (e.type() != Object)
return Status(ErrorCodes::BadValue, "$or/$and/$nor entries need to be full objects");
- StatusWithMatchExpression sub = _parse(e.Obj(), collator, expCtx, topLevel);
+ StatusWithMatchExpression sub =
+ _parse(e.Obj(), collator, expCtx, allowedFeatures, topLevel);
if (!sub.isOK())
return sub.getStatus();
@@ -68,6 +70,7 @@ StatusWithMatchExpression MatchExpressionParser::_parseNot(
const BSONElement& e,
const CollatorInterface* collator,
const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ AllowedFeatureSet allowedFeatures,
bool topLevel) {
if (e.type() == RegEx) {
StatusWithMatchExpression s = _parseRegexElement(name, e, expCtx);
@@ -88,7 +91,8 @@ StatusWithMatchExpression MatchExpressionParser::_parseNot(
return StatusWithMatchExpression(ErrorCodes::BadValue, "$not cannot be empty");
std::unique_ptr<AndMatchExpression> theAnd = stdx::make_unique<AndMatchExpression>();
- Status s = _parseSub(name, notObject, theAnd.get(), collator, expCtx, topLevel);
+ Status s =
+ _parseSub(name, notObject, theAnd.get(), collator, expCtx, allowedFeatures, topLevel);
if (!s.isOK())
return StatusWithMatchExpression(s);
diff --git a/src/mongo/db/matcher/expression_parser_tree_test.cpp b/src/mongo/db/matcher/expression_parser_tree_test.cpp
index 1fbed8b69a6..d223a672c95 100644
--- a/src/mongo/db/matcher/expression_parser_tree_test.cpp
+++ b/src/mongo/db/matcher/expression_parser_tree_test.cpp
@@ -36,15 +36,13 @@
#include "mongo/db/json.h"
#include "mongo/db/matcher/expression.h"
#include "mongo/db/matcher/expression_leaf.h"
-#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
namespace mongo {
TEST(MatchExpressionParserTreeTest, OR1) {
BSONObj query = BSON("$or" << BSON_ARRAY(BSON("x" << 1) << BSON("y" << 2)));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -57,8 +55,7 @@ TEST(MatchExpressionParserTreeTest, OREmbedded) {
BSONObj query1 = BSON("$or" << BSON_ARRAY(BSON("x" << 1) << BSON("y" << 2)));
BSONObj query2 = BSON("$or" << BSON_ARRAY(query1));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query2, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query2, collator);
ASSERT_TRUE(result.isOK());
ASSERT(result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -71,8 +68,7 @@ TEST(MatchExpressionParserTreeTest, OREmbedded) {
TEST(MatchExpressionParserTreeTest, AND1) {
BSONObj query = BSON("$and" << BSON_ARRAY(BSON("x" << 1) << BSON("y" << 2)));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -86,8 +82,7 @@ TEST(MatchExpressionParserTreeTest, AND1) {
TEST(MatchExpressionParserTreeTest, NOREmbedded) {
BSONObj query = BSON("$nor" << BSON_ARRAY(BSON("x" << 1) << BSON("y" << 2)));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -99,8 +94,7 @@ TEST(MatchExpressionParserTreeTest, NOREmbedded) {
TEST(MatchExpressionParserTreeTest, NOT1) {
BSONObj query = BSON("x" << BSON("$not" << BSON("$gt" << 5)));
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(result.getValue()->matchesBSON(BSON("x" << 2)));
@@ -112,8 +106,7 @@ TEST(MatchExpressionParserLeafTest, NotRegex1) {
b.appendRegex("$not", "abc", "i");
BSONObj query = BSON("x" << b.obj());
const CollatorInterface* collator = nullptr;
- StatusWithMatchExpression result =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x"
diff --git a/src/mongo/db/matcher/expression_serialization_test.cpp b/src/mongo/db/matcher/expression_serialization_test.cpp
index 0f08fedebb7..6ab93f3e2dc 100644
--- a/src/mongo/db/matcher/expression_serialization_test.cpp
+++ b/src/mongo/db/matcher/expression_serialization_test.cpp
@@ -33,9 +33,9 @@
#include "mongo/db/json.h"
#include "mongo/db/matcher/expression.h"
#include "mongo/db/matcher/expression_parser.h"
-#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
#include "mongo/db/matcher/extensions_callback_noop.h"
#include "mongo/db/matcher/matcher.h"
+#include "mongo/db/pipeline/expression_context_for_test.h"
#include "mongo/unittest/unittest.h"
namespace mongo {
@@ -54,9 +54,17 @@ BSONObj serialize(MatchExpression* match) {
}
TEST(SerializeBasic, AndExpressionWithOneChildSerializesCorrectly) {
- Matcher original(fromjson("{$and: [{x: 0}]}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{$and: [{x: 0}]}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{$and: [{x: {$eq: 0}}]}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -68,10 +76,17 @@ TEST(SerializeBasic, AndExpressionWithOneChildSerializesCorrectly) {
}
TEST(SerializeBasic, AndExpressionWithTwoChildrenSerializesCorrectly) {
- Matcher original(
- fromjson("{$and: [{x: 1}, {x: 2}]}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{$and: [{x: 1}, {x: 2}]}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{$and: [{x: {$eq: 1}}, {x: {$eq: 2}}]}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -83,10 +98,17 @@ TEST(SerializeBasic, AndExpressionWithTwoChildrenSerializesCorrectly) {
}
TEST(SerializeBasic, AndExpressionWithTwoIdenticalChildrenSerializesCorrectly) {
- Matcher original(
- fromjson("{$and: [{x: 1}, {x: 1}]}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{$and: [{x: 1}, {x: 1}]}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{$and: [{x: {$eq: 1}}, {x: {$eq: 1}}]}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -98,10 +120,17 @@ TEST(SerializeBasic, AndExpressionWithTwoIdenticalChildrenSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionOr) {
- Matcher original(
- fromjson("{$or: [{x: 'A'}, {x: 'B'}]}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{$or: [{x: 'A'}, {x: 'B'}]}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
fromjson("{$or: [{x: {$eq: 'A'}}, {x: {$eq: 'B'}}]}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -114,11 +143,17 @@ TEST(SerializeBasic, ExpressionOr) {
}
TEST(SerializeBasic, ExpressionElemMatchObjectSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(fromjson("{x: {$elemMatch: {a: {$gt: 0}, b: {$gt: 0}}}}"),
+ kSimpleCollator,
+ expCtx,
ExtensionsCallbackNoop(),
- kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
fromjson("{x: {$elemMatch: {$and: [{a: {$gt: 0}}, {b: {$gt: 0}}]}}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -131,11 +166,17 @@ TEST(SerializeBasic, ExpressionElemMatchObjectSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionElemMatchObjectWithEmptyStringSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(fromjson("{'': {$elemMatch: {a: {$gt: 0}, b: {$gt: 0}}}}"),
+ kSimpleCollator,
+ expCtx,
ExtensionsCallbackNoop(),
- kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
fromjson("{'': {$elemMatch: {$and: [{a: {$gt: 0}}, {b: {$gt: 0}}]}}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -148,11 +189,17 @@ TEST(SerializeBasic, ExpressionElemMatchObjectWithEmptyStringSerializesCorrectly
}
TEST(SerializeBasic, ExpressionElemMatchValueSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(fromjson("{x: {$elemMatch: {$lt: 1, $gt: -1}}}"),
+ kSimpleCollator,
+ expCtx,
ExtensionsCallbackNoop(),
- kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$elemMatch: {$lt: 1, $gt: -1}}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -167,13 +214,21 @@ TEST(SerializeBasic, ExpressionElemMatchValueSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionElemMatchValueWithRegexSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
const auto match = BSON("x" << BSON("$elemMatch" << BSON("$regex"
<< "abc"
<< "$options"
<< "i")));
- Matcher original(match, ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ Matcher original(match,
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), match);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -188,11 +243,17 @@ TEST(SerializeBasic, ExpressionElemMatchValueWithRegexSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionElemMatchValueWithEmptyStringSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(fromjson("{x: {$elemMatch: {$lt: 1, $gt: -1}}}"),
+ kSimpleCollator,
+ expCtx,
ExtensionsCallbackNoop(),
- kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$elemMatch: {$lt: 1, $gt: -1}}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -207,9 +268,17 @@ TEST(SerializeBasic, ExpressionElemMatchValueWithEmptyStringSerializesCorrectly)
}
TEST(SerializeBasic, ExpressionSizeSerializesCorrectly) {
- Matcher original(fromjson("{x: {$size: 2}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$size: 2}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$size: 2}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -221,9 +290,17 @@ TEST(SerializeBasic, ExpressionSizeSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionAllSerializesCorrectly) {
- Matcher original(fromjson("{x: {$all: [1, 2]}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$all: [1, 2]}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{$and: [{x: {$eq: 1}}, {x: {$eq: 2}}]}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -235,9 +312,17 @@ TEST(SerializeBasic, ExpressionAllSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionAllWithEmptyArraySerializesCorrectly) {
- Matcher original(fromjson("{x: {$all: []}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$all: []}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{$alwaysFalse: 1}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -246,10 +331,17 @@ TEST(SerializeBasic, ExpressionAllWithEmptyArraySerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionAllWithRegex) {
- Matcher original(
- fromjson("{x: {$all: [/a.b.c/, /.d.e./]}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$all: [/a.b.c/, /.d.e./]}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
BSON("$and" << BSON_ARRAY(BSON("x" << BSON("$regex"
@@ -266,9 +358,17 @@ TEST(SerializeBasic, ExpressionAllWithRegex) {
}
TEST(SerializeBasic, ExpressionEqSerializesCorrectly) {
- Matcher original(fromjson("{x: {$eq: {a: 1}}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$eq: {a: 1}}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$eq: {a: 1}}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -283,9 +383,17 @@ TEST(SerializeBasic, ExpressionEqSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionNeSerializesCorrectly) {
- Matcher original(fromjson("{x: {$ne: {a: 1}}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$ne: {a: 1}}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{$nor: [{x: {$eq: {a: 1}}}]}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -297,12 +405,18 @@ TEST(SerializeBasic, ExpressionNeSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionNeWithRegexObjectSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(BSON("x" << BSON("$ne" << BSON("$regex"
<< "abc"))),
+ kSimpleCollator,
+ expCtx,
ExtensionsCallbackNoop(),
- kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
BSON("$nor" << BSON_ARRAY(BSON("x" << BSON("$eq" << BSON("$regex"
<< "abc"))))));
@@ -316,9 +430,17 @@ TEST(SerializeBasic, ExpressionNeWithRegexObjectSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionLtSerializesCorrectly) {
- Matcher original(fromjson("{x: {$lt: 3}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$lt: 3}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$lt: 3}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -330,9 +452,17 @@ TEST(SerializeBasic, ExpressionLtSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionGtSerializesCorrectly) {
- Matcher original(fromjson("{x: {$gt: 3}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$gt: 3}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$gt: 3}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -344,9 +474,17 @@ TEST(SerializeBasic, ExpressionGtSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionGteSerializesCorrectly) {
- Matcher original(fromjson("{x: {$gte: 3}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$gte: 3}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$gte: 3}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -358,9 +496,17 @@ TEST(SerializeBasic, ExpressionGteSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionLteSerializesCorrectly) {
- Matcher original(fromjson("{x: {$lte: 3}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$lte: 3}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$lte: 3}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -372,9 +518,17 @@ TEST(SerializeBasic, ExpressionLteSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionRegexWithObjSerializesCorrectly) {
- Matcher original(fromjson("{x: {$regex: 'a.b'}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$regex: 'a.b'}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
BSON("x" << BSON("$regex"
<< "a.b")));
@@ -388,9 +542,17 @@ TEST(SerializeBasic, ExpressionRegexWithObjSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionRegexWithValueAndOptionsSerializesCorrectly) {
- Matcher original(fromjson("{x: /a.b/i}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: /a.b/i}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
BSON("x" << BSON("$regex"
<< "a.b"
@@ -406,9 +568,17 @@ TEST(SerializeBasic, ExpressionRegexWithValueAndOptionsSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionRegexWithValueSerializesCorrectly) {
- Matcher original(fromjson("{x: /a.b/}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: /a.b/}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
BSON("x" << BSON("$regex"
<< "a.b")));
@@ -422,10 +592,17 @@ TEST(SerializeBasic, ExpressionRegexWithValueSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionRegexWithEqObjSerializesCorrectly) {
- Matcher original(
- fromjson("{x: {$eq: {$regex: 'a.b'}}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$eq: {$regex: 'a.b'}}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$eq: {$regex: 'a.b'}}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -440,9 +617,17 @@ TEST(SerializeBasic, ExpressionRegexWithEqObjSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionModSerializesCorrectly) {
- Matcher original(fromjson("{x: {$mod: [2, 1]}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$mod: [2, 1]}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$mod: [2, 1]}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -454,9 +639,17 @@ TEST(SerializeBasic, ExpressionModSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionExistsTrueSerializesCorrectly) {
- Matcher original(fromjson("{x: {$exists: true}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$exists: true}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$exists: true}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -468,9 +661,17 @@ TEST(SerializeBasic, ExpressionExistsTrueSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionExistsFalseSerializesCorrectly) {
- Matcher original(fromjson("{x: {$exists: false}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$exists: false}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{$nor: [{x: {$exists: true}}]}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -482,9 +683,17 @@ TEST(SerializeBasic, ExpressionExistsFalseSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionInSerializesCorrectly) {
- Matcher original(fromjson("{x: {$in: [1, 2, 3]}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$in: [1, 2, 3]}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$in: [1, 2, 3]}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -499,9 +708,17 @@ TEST(SerializeBasic, ExpressionInSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionInWithEmptyArraySerializesCorrectly) {
- Matcher original(fromjson("{x: {$in: []}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$in: []}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$in: []}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -510,10 +727,17 @@ TEST(SerializeBasic, ExpressionInWithEmptyArraySerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionInWithRegexSerializesCorrectly) {
- Matcher original(
- fromjson("{x: {$in: [/\\d+/, /\\w+/]}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$in: [/\\d+/, /\\w+/]}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$in: [/\\d+/, /\\w+/]}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -528,9 +752,17 @@ TEST(SerializeBasic, ExpressionInWithRegexSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionNinSerializesCorrectly) {
- Matcher original(fromjson("{x: {$nin: [1, 2, 3]}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$nin: [1, 2, 3]}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{$nor: [{x: {$in: [1, 2, 3]}}]}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -545,10 +777,17 @@ TEST(SerializeBasic, ExpressionNinSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionNinWithRegexValueSerializesCorrectly) {
- Matcher original(
- fromjson("{x: {$nin: [/abc/, /def/, /xyz/]}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$nin: [/abc/, /def/, /xyz/]}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
fromjson("{$nor: [{x: {$in: [/abc/, /def/, /xyz/]}}]}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -563,10 +802,17 @@ TEST(SerializeBasic, ExpressionNinWithRegexValueSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionBitsAllSetSerializesCorrectly) {
- Matcher original(
- fromjson("{x: {$bitsAllSet: [1, 3]}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$bitsAllSet: [1, 3]}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$bitsAllSet: [1, 3]}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -578,10 +824,17 @@ TEST(SerializeBasic, ExpressionBitsAllSetSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionBitsAllClearSerializesCorrectly) {
- Matcher original(
- fromjson("{x: {$bitsAllClear: [1, 3]}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$bitsAllClear: [1, 3]}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$bitsAllClear: [1, 3]}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -593,10 +846,17 @@ TEST(SerializeBasic, ExpressionBitsAllClearSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionBitsAnySetSerializesCorrectly) {
- Matcher original(
- fromjson("{x: {$bitsAnySet: [1, 3]}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$bitsAnySet: [1, 3]}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$bitsAnySet: [1, 3]}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -608,10 +868,17 @@ TEST(SerializeBasic, ExpressionBitsAnySetSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionBitsAnyClearSerializesCorrectly) {
- Matcher original(
- fromjson("{x: {$bitsAnyClear: [1, 3]}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$bitsAnyClear: [1, 3]}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$bitsAnyClear: [1, 3]}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -626,9 +893,17 @@ TEST(SerializeBasic, ExpressionBitsAnyClearSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionNotSerializesCorrectly) {
- Matcher original(fromjson("{x: {$not: {$eq: 3}}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$not: {$eq: 3}}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{$nor: [{$and: [{x: {$eq: 3}}]}]}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -640,10 +915,17 @@ TEST(SerializeBasic, ExpressionNotSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionNotWithMultipleChildrenSerializesCorrectly) {
- Matcher original(
- fromjson("{x: {$not: {$lt: 1, $gt: 3}}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$not: {$lt: 1, $gt: 3}}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
fromjson("{$nor: [{$and: [{x: {$lt: 1}}, {x: {$gt: 3}}]}]}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -656,10 +938,17 @@ TEST(SerializeBasic, ExpressionNotWithMultipleChildrenSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionNotWithBitTestSerializesCorrectly) {
- Matcher original(
- fromjson("{x: {$not: {$bitsAnySet: [1, 3]}}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$not: {$bitsAnySet: [1, 3]}}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
fromjson("{$nor: [{$and: [{x: {$bitsAnySet: [1, 3]}}]}]}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -672,10 +961,17 @@ TEST(SerializeBasic, ExpressionNotWithBitTestSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionNotWithRegexObjSerializesCorrectly) {
- Matcher original(
- fromjson("{x: {$not: {$regex: 'a.b'}}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$not: {$regex: 'a.b'}}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
BSON("$nor" << BSON_ARRAY(BSON("x" << BSON("$regex"
<< "a.b")))));
@@ -689,9 +985,17 @@ TEST(SerializeBasic, ExpressionNotWithRegexObjSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionNotWithRegexValueSerializesCorrectly) {
- Matcher original(fromjson("{x: {$not: /a.b/}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$not: /a.b/}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
BSON("$nor" << BSON_ARRAY(BSON("x" << BSON("$regex"
<< "a.b")))));
@@ -705,9 +1009,17 @@ TEST(SerializeBasic, ExpressionNotWithRegexValueSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionNotWithRegexValueAndOptionsSerializesCorrectly) {
- Matcher original(fromjson("{x: {$not: /a.b/i}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$not: /a.b/i}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
BSON("$nor" << BSON_ARRAY(BSON("x" << BSON("$regex"
<< "a.b"
@@ -723,13 +1035,19 @@ TEST(SerializeBasic, ExpressionNotWithRegexValueAndOptionsSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionNotWithGeoSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(fromjson("{x: {$not: {$geoIntersects: {$geometry: {type: 'Polygon', "
"coordinates: [[[0,0], [5,0], "
"[5, 5], [0, 5], [0, 0]]]}}}}}"),
+ kSimpleCollator,
+ expCtx,
ExtensionsCallbackNoop(),
- kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(
*reserialized.getQuery(),
fromjson("{$nor: [{$and: [{x: {$geoIntersects: {$geometry: {type: 'Polygon', coordinates: "
@@ -752,10 +1070,17 @@ TEST(SerializeBasic, ExpressionNotWithGeoSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionNorSerializesCorrectly) {
- Matcher original(
- fromjson("{$nor: [{x: 3}, {x: {$lt: 1}}]}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{$nor: [{x: 3}, {x: {$lt: 1}}]}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{$nor: [{x: {$eq: 3}}, {x: {$lt: 1}}]}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -770,9 +1095,17 @@ TEST(SerializeBasic, ExpressionNorSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionTypeSerializesCorrectly) {
- Matcher original(fromjson("{x: {$type: 2}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$type: 2}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$type: 2}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -784,9 +1117,17 @@ TEST(SerializeBasic, ExpressionTypeSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionTypeWithNumberSerializesCorrectly) {
- Matcher original(fromjson("{x: {$type: 'number'}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{x: {$type: 'number'}}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$type: 'number'}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -798,10 +1139,8 @@ TEST(SerializeBasic, ExpressionTypeWithNumberSerializesCorrectly) {
}
TEST(SerializeInternalSchema, InternalSchemaTypeExpressionSerializesCorrectly) {
- Matcher original(
- fromjson("{x: {$_internalSchemaType: 2}}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ Matcher original(fromjson("{x: {$_internalSchemaType: 2}}"), kSimpleCollator);
+ Matcher reserialized(serialize(original.getMatchExpression()), kSimpleCollator);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$_internalSchemaType: 2}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -813,11 +1152,8 @@ TEST(SerializeInternalSchema, InternalSchemaTypeExpressionSerializesCorrectly) {
}
TEST(SerializeInternalSchema, InternalSchemaTypeExpressionWithNumberSerializesCorrectly) {
- Matcher original(fromjson("{x: {$_internalSchemaType: 'number'}}"),
- ExtensionsCallbackNoop(),
- kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ Matcher original(fromjson("{x: {$_internalSchemaType: 'number'}}"), kSimpleCollator);
+ Matcher reserialized(serialize(original.getMatchExpression()), kSimpleCollator);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$_internalSchemaType: 'number'}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -829,9 +1165,17 @@ TEST(SerializeInternalSchema, InternalSchemaTypeExpressionWithNumberSerializesCo
}
TEST(SerializeBasic, ExpressionEmptySerializesCorrectly) {
- Matcher original(fromjson("{}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -840,10 +1184,17 @@ TEST(SerializeBasic, ExpressionEmptySerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionWhereSerializesCorrectly) {
- Matcher original(
- fromjson("{$where: 'this.a == this.b'}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{$where: 'this.a == this.b'}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(
*reserialized.getQuery(),
BSONObjBuilder().appendCodeWScope("$where", "this.a == this.b", BSONObj()).obj());
@@ -851,20 +1202,34 @@ TEST(SerializeBasic, ExpressionWhereSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionWhereWithScopeSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(BSON("$where" << BSONCodeWScope("this.a == this.b", BSON("x" << 3))),
+ kSimpleCollator,
+ expCtx,
ExtensionsCallbackNoop(),
- kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
BSON("$where" << BSONCodeWScope("this.a == this.b", BSON("x" << 3))));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
}
TEST(SerializeBasic, ExpressionCommentSerializesCorrectly) {
- Matcher original(fromjson("{$comment: 'Hello'}"), ExtensionsCallbackNoop(), kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{$comment: 'Hello'}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
@@ -876,14 +1241,20 @@ TEST(SerializeBasic, ExpressionCommentSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionGeoWithinSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(
fromjson(
"{x: {$geoWithin: {$geometry: "
"{type: 'Polygon', coordinates: [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]]}}}}"),
+ kSimpleCollator,
+ expCtx,
ExtensionsCallbackNoop(),
- kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(
*reserialized.getQuery(),
fromjson("{x: {$geoWithin: {$geometry: {type: 'Polygon', coordinates: [[[0,0], [10,0], "
@@ -898,14 +1269,20 @@ TEST(SerializeBasic, ExpressionGeoWithinSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionGeoIntersectsSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(
fromjson(
"{x: {$geoIntersects: {$geometry: {type: 'Polygon', coordinates: [[[0,0], [5,0], [5, "
"5], [0, 5], [0, 0]]]}}}}"),
+ kSimpleCollator,
+ expCtx,
ExtensionsCallbackNoop(),
- kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(
*reserialized.getQuery(),
fromjson("{x: {$geoIntersects: {$geometry: {type: 'Polygon', coordinates: [[[0,0], [5,0], "
@@ -927,13 +1304,19 @@ TEST(SerializeBasic, ExpressionGeoIntersectsSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionNearSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(
fromjson("{x: {$near: {$geometry: {type: 'Point', coordinates: [0, 0]}, $maxDistance: 10, "
"$minDistance: 1}}}"),
+ kSimpleCollator,
+ expCtx,
ExtensionsCallbackNoop(),
- kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(
*reserialized.getQuery(),
fromjson("{x: {$near: {$geometry: {type: 'Point', coordinates: [0, 0]}, $maxDistance: 10, "
@@ -942,14 +1325,20 @@ TEST(SerializeBasic, ExpressionNearSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionNearSphereSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(
fromjson(
"{x: {$nearSphere: {$geometry: {type: 'Point', coordinates: [0, 0]}, $maxDistance: 10, "
"$minDistance: 1}}}"),
+ kSimpleCollator,
+ expCtx,
ExtensionsCallbackNoop(),
- kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(
*reserialized.getQuery(),
fromjson("{x: {$nearSphere: {$geometry: {type: 'Point', coordinates: [0, 0]}, "
@@ -958,11 +1347,17 @@ TEST(SerializeBasic, ExpressionNearSphereSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionTextSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(fromjson("{$text: {$search: 'a', $language: 'en', $caseSensitive: true}}"),
+ kSimpleCollator,
+ expCtx,
ExtensionsCallbackNoop(),
- kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
fromjson("{$text: {$search: 'a', $language: 'en', $caseSensitive: true, "
"$diacriticSensitive: false}}"));
@@ -970,11 +1365,17 @@ TEST(SerializeBasic, ExpressionTextSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionTextWithDefaultLanguageSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(fromjson("{$text: {$search: 'a', $caseSensitive: false}}"),
+ kSimpleCollator,
+ expCtx,
ExtensionsCallbackNoop(),
- kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
fromjson("{$text: {$search: 'a', $language: '', $caseSensitive: false, "
"$diacriticSensitive: false}}"));
@@ -982,110 +1383,162 @@ TEST(SerializeBasic, ExpressionTextWithDefaultLanguageSerializesCorrectly) {
}
TEST(SerializeBasic, ExpressionAlwaysTrueSerializesCorrectly) {
- Matcher original(
- fromjson("{$alwaysTrue: 1}"), ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{$alwaysTrue: 1}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
Matcher reserialized(serialize(original.getMatchExpression()),
- ExtensionsCallbackDisallowExtensions(),
- kSimpleCollator);
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{$alwaysTrue: 1}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
}
TEST(SerializeBasic, ExpressionAlwaysFalseSerializesCorrectly) {
- Matcher original(
- fromjson("{$alwaysFalse: 1}"), ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{$alwaysFalse: 1}"),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
Matcher reserialized(serialize(original.getMatchExpression()),
- ExtensionsCallbackDisallowExtensions(),
- kSimpleCollator);
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{$alwaysFalse: 1}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
}
TEST(SerializeInternalSchema, ExpressionInternalSchemaAllElemMatchFromIndexSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(fromjson("{x: {$_internalSchemaAllElemMatchFromIndex: [2, {y: 1}]}}"),
- ExtensionsCallbackDisallowExtensions(),
- kSimpleCollator);
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
Matcher reserialized(serialize(original.getMatchExpression()),
- ExtensionsCallbackDisallowExtensions(),
- kSimpleCollator);
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
fromjson("{x: {$_internalSchemaAllElemMatchFromIndex: [2, {y: {$eq: 1}}]}}"));
}
TEST(SerializeInternalSchema, ExpressionInternalSchemaMinItemsSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(fromjson("{x: {$_internalSchemaMinItems: 1}}"),
- ExtensionsCallbackDisallowExtensions(),
- kSimpleCollator);
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
Matcher reserialized(serialize(original.getMatchExpression()),
- ExtensionsCallbackDisallowExtensions(),
- kSimpleCollator);
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$_internalSchemaMinItems: 1}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
}
TEST(SerializeInternalSchema, ExpressionInternalSchemaMaxItemsSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(fromjson("{x: {$_internalSchemaMaxItems: 1}}"),
- ExtensionsCallbackDisallowExtensions(),
- kSimpleCollator);
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
Matcher reserialized(serialize(original.getMatchExpression()),
- ExtensionsCallbackDisallowExtensions(),
- kSimpleCollator);
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$_internalSchemaMaxItems: 1}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
}
TEST(SerializeInternalSchema, ExpressionInternalSchemaUniqueItemsSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(fromjson("{x: {$_internalSchemaUniqueItems: true}}"),
- ExtensionsCallbackDisallowExtensions(),
- kSimpleCollator);
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
Matcher reserialized(serialize(original.getMatchExpression()),
- ExtensionsCallbackDisallowExtensions(),
- kSimpleCollator);
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
fromjson("{x: {$_internalSchemaUniqueItems: true}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
}
TEST(SerializeInternalSchema, ExpressionInternalSchemaObjectMatchSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(fromjson("{x: {$_internalSchemaObjectMatch: {y: 1}}}"),
- ExtensionsCallbackDisallowExtensions(),
- kSimpleCollator);
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
Matcher reserialized(serialize(original.getMatchExpression()),
- ExtensionsCallbackDisallowExtensions(),
- kSimpleCollator);
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
fromjson("{x: {$_internalSchemaObjectMatch: {y: {$eq: 1}}}}"));
}
TEST(SerializeInternalSchema, ExpressionInternalSchemaMinLengthSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(fromjson("{x: {$_internalSchemaMinLength: 1}}"),
- ExtensionsCallbackDisallowExtensions(),
- kSimpleCollator);
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
Matcher reserialized(serialize(original.getMatchExpression()),
- ExtensionsCallbackDisallowExtensions(),
- kSimpleCollator);
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$_internalSchemaMinLength: 1}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
}
TEST(SerializeInternalSchema, ExpressionInternalSchemaMaxLengthSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(fromjson("{x: {$_internalSchemaMaxLength: 1}}"),
- ExtensionsCallbackDisallowExtensions(),
- kSimpleCollator);
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
Matcher reserialized(serialize(original.getMatchExpression()),
- ExtensionsCallbackDisallowExtensions(),
- kSimpleCollator);
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{x: {$_internalSchemaMaxLength: 1}}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
}
TEST(SerializeInternalSchema, ExpressionInternalSchemaCondSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(fromjson("{$_internalSchemaCond: [{a: 1}, {b: 2}, {c: 3}]}}"),
- ExtensionsCallbackDisallowExtensions(),
- kSimpleCollator);
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
Matcher reserialized(serialize(original.getMatchExpression()),
- ExtensionsCallbackDisallowExtensions(),
- kSimpleCollator);
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
BSONObjBuilder builder;
ASSERT_BSONOBJ_EQ(
*reserialized.getQuery(),
@@ -1094,34 +1547,52 @@ TEST(SerializeInternalSchema, ExpressionInternalSchemaCondSerializesCorrectly) {
}
TEST(SerializeInternalSchema, ExpressionInternalSchemaMinPropertiesSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
const CollatorInterface* collator = nullptr;
Matcher original(fromjson("{$_internalSchemaMinProperties: 1}"),
- ExtensionsCallbackDisallowExtensions(),
- collator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackDisallowExtensions(), collator);
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{$_internalSchemaMinProperties: 1}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
}
TEST(SerializeInternalSchema, ExpressionInternalSchemaMaxPropertiesSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
const CollatorInterface* collator = nullptr;
Matcher original(fromjson("{$_internalSchemaMaxProperties: 1}"),
- ExtensionsCallbackDisallowExtensions(),
- collator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackDisallowExtensions(), collator);
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson("{$_internalSchemaMaxProperties: 1}"));
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
}
TEST(SerializeInternalSchema, ExpressionInternalSchemaFmodSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(
fromjson("{a: {$_internalSchemaFmod: [NumberDecimal('2.3'), NumberDecimal('1.1')]}}"),
+ kSimpleCollator,
+ expCtx,
ExtensionsCallbackNoop(),
- kSimpleCollator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackNoop(), kSimpleCollator);
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ kSimpleCollator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(
*reserialized.getQuery(),
@@ -1134,13 +1605,19 @@ TEST(SerializeInternalSchema, ExpressionInternalSchemaFmodSerializesCorrectly) {
}
TEST(SerializeInternalSchema, ExpressionInternalSchemaMatchArrayIndexSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
constexpr CollatorInterface* collator = nullptr;
Matcher original(fromjson("{a: {$_internalSchemaMatchArrayIndex:"
"{index: 2, namePlaceholder: 'i', expression: {i: {$lt: 3}}}}}"),
- ExtensionsCallbackDisallowExtensions(),
- collator);
- Matcher reserialized(
- serialize(original.getMatchExpression()), ExtensionsCallbackDisallowExtensions(), collator);
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ collator,
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
fromjson("{a: {$_internalSchemaMatchArrayIndex:"
"{index: 2, namePlaceholder: 'i', expression: {i: {$lt: 3}}}}}"));
@@ -1154,11 +1631,8 @@ TEST(SerializeInternalSchema, ExpressionInternalSchemaAllowedPropertiesSerialize
namePlaceholder: 'i',
patternProperties: [{regex: /b/, expression: {i: {$type: 'number'}}}]
}})"),
- ExtensionsCallbackDisallowExtensions(),
kSimpleCollator);
- Matcher reserialized(serialize(original.getMatchExpression()),
- ExtensionsCallbackDisallowExtensions(),
- kSimpleCollator);
+ Matcher reserialized(serialize(original.getMatchExpression()), kSimpleCollator);
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), fromjson(R"({$_internalSchemaAllowedProperties: {
properties: ['a'],
namePlaceholder: 'i',
diff --git a/src/mongo/db/matcher/expression_text.h b/src/mongo/db/matcher/expression_text.h
index bb5dbfb77b1..2a3ac4a3c36 100644
--- a/src/mongo/db/matcher/expression_text.h
+++ b/src/mongo/db/matcher/expression_text.h
@@ -47,6 +47,21 @@ public:
return _ftsQuery;
}
+ bool matchesSingleElement(const BSONElement& e, MatchDetails* details = nullptr) const final {
+ // Text match expressions force the selection of the text index and always generate EXACT
+ // index bounds (which causes the MatchExpression node to be trimmed), so we don't currently
+ // implement any explicit text matching logic here. SERVER-17648 tracks the work to
+ // implement a real text matcher.
+ //
+ // TODO: simply returning 'true' here isn't quite correct. First, we should be overriding
+ // matches() instead of matchesSingleElement(), because the latter is only ever called if
+ // the matched document has an element with path "_fts". Second, there are scenarios where
+ // we will use the untrimmed expression tree for matching (for example, when deciding
+ // whether or not to retry an operation that throws WriteConflictException); in those cases,
+ // we won't be able to correctly determine whether or not the object matches the expression.
+ return true;
+ }
+
std::unique_ptr<MatchExpression> shallowClone() const final;
private:
diff --git a/src/mongo/db/matcher/expression_text_base.h b/src/mongo/db/matcher/expression_text_base.h
index 65b38f90b43..045a9d88a32 100644
--- a/src/mongo/db/matcher/expression_text_base.h
+++ b/src/mongo/db/matcher/expression_text_base.h
@@ -63,21 +63,6 @@ public:
// Methods inherited from MatchExpression.
//
- bool matchesSingleElement(const BSONElement& e, MatchDetails* details = nullptr) const final {
- // Text match expressions force the selection of the text index and always generate EXACT
- // index bounds (which causes the MatchExpression node to be trimmed), so we don't currently
- // implement any explicit text matching logic here. SERVER-17648 tracks the work to
- // implement a real text matcher.
- //
- // TODO: simply returning 'true' here isn't quite correct. First, we should be overriding
- // matches() instead of matchesSingleElement(), because the latter is only ever called if
- // the matched document has an element with path "_fts". Second, there are scenarios where
- // we will use the untrimmed expression tree for matching (for example, when deciding
- // whether or not to retry an operation that throws WriteConflictException); in those cases,
- // we won't be able to correctly determine whether or not the object matches the expression.
- return true;
- }
-
void debugString(StringBuilder& debug, int level = 0) const final;
void serialize(BSONObjBuilder* out) const final;
diff --git a/src/mongo/db/matcher/expression_text_noop.h b/src/mongo/db/matcher/expression_text_noop.h
index 8e01d40e70b..429fecff05d 100644
--- a/src/mongo/db/matcher/expression_text_noop.h
+++ b/src/mongo/db/matcher/expression_text_noop.h
@@ -41,6 +41,10 @@ public:
return _ftsQuery;
}
+ bool matchesSingleElement(const BSONElement& e, MatchDetails* details = nullptr) const final {
+ MONGO_UNREACHABLE;
+ }
+
std::unique_ptr<MatchExpression> shallowClone() const final;
private:
diff --git a/src/mongo/db/matcher/expression_where_noop.cpp b/src/mongo/db/matcher/expression_where_noop.cpp
index 23bb7c287e5..c65bf70019c 100644
--- a/src/mongo/db/matcher/expression_where_noop.cpp
+++ b/src/mongo/db/matcher/expression_where_noop.cpp
@@ -40,7 +40,7 @@ WhereNoOpMatchExpression::WhereNoOpMatchExpression(WhereParams params)
: WhereMatchExpressionBase(std::move(params)) {}
bool WhereNoOpMatchExpression::matches(const MatchableDocument* doc, MatchDetails* details) const {
- return false;
+ MONGO_UNREACHABLE;
}
std::unique_ptr<MatchExpression> WhereNoOpMatchExpression::shallowClone() const {
diff --git a/src/mongo/db/matcher/expression_with_placeholder.cpp b/src/mongo/db/matcher/expression_with_placeholder.cpp
index 34771d2cc8a..97158b6ab33 100644
--- a/src/mongo/db/matcher/expression_with_placeholder.cpp
+++ b/src/mongo/db/matcher/expression_with_placeholder.cpp
@@ -32,8 +32,6 @@
#include <regex>
-#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
-
namespace mongo {
namespace {
@@ -105,8 +103,7 @@ const std::regex ExpressionWithPlaceholder::placeholderRegex("^[a-z][a-zA-Z0-9]*
// static
StatusWith<std::unique_ptr<ExpressionWithPlaceholder>> ExpressionWithPlaceholder::parse(
BSONObj rawFilter, const CollatorInterface* collator) {
- StatusWithMatchExpression statusWithFilter =
- MatchExpressionParser::parse(rawFilter, ExtensionsCallbackDisallowExtensions(), collator);
+ StatusWithMatchExpression statusWithFilter = MatchExpressionParser::parse(rawFilter, collator);
if (!statusWithFilter.isOK()) {
return statusWithFilter.getStatus();
diff --git a/src/mongo/db/matcher/expression_with_placeholder_test.cpp b/src/mongo/db/matcher/expression_with_placeholder_test.cpp
index 8fd5f4e456f..bb8abef57ef 100644
--- a/src/mongo/db/matcher/expression_with_placeholder_test.cpp
+++ b/src/mongo/db/matcher/expression_with_placeholder_test.cpp
@@ -30,7 +30,6 @@
#include "mongo/db/json.h"
#include "mongo/db/matcher/expression_with_placeholder.h"
-#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
#include "mongo/db/query/collation/collator_interface_mock.h"
#include "mongo/unittest/unittest.h"
@@ -178,6 +177,21 @@ TEST(ExpressionWithPlaceholderTest, WhereExpressionFailsToParse) {
ASSERT_NOT_OK(status.getStatus());
}
+TEST(ExpressionWithPlaceholderTest, GeoNearExpressionFailsToParse) {
+ const CollatorInterface* collator = nullptr;
+ auto rawFilter =
+ fromjson("{i: {$nearSphere: {$geometry: {type: 'Point', coordinates: [0, 0]}}}}");
+ auto status = ExpressionWithPlaceholder::parse(rawFilter, collator);
+ ASSERT_NOT_OK(status.getStatus());
+}
+
+TEST(ExpressionWithPlaceholderTest, ExprExpressionFailsToParse) {
+ const CollatorInterface* collator = nullptr;
+ auto rawFilter = fromjson("{i: {$expr: 5}}");
+ auto status = ExpressionWithPlaceholder::parse(rawFilter, collator);
+ ASSERT_NOT_OK(status.getStatus());
+}
+
TEST(ExpressionWithPlaceholderTest, EquivalentIfPlaceholderAndExpressionMatch) {
constexpr auto collator = nullptr;
auto rawFilter1 = fromjson("{i: 5}}");
diff --git a/src/mongo/db/matcher/extensions_callback_disallow_extensions.cpp b/src/mongo/db/matcher/extensions_callback_disallow_extensions.cpp
deleted file mode 100644
index 2c68c97a23a..00000000000
--- a/src/mongo/db/matcher/extensions_callback_disallow_extensions.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * Copyright (C) 2015 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
-
-namespace mongo {
-
-StatusWithMatchExpression ExtensionsCallbackDisallowExtensions::parseWhere(
- BSONElement where) const {
- return {Status(ErrorCodes::NoMatchParseContext, "no context for parsing $where")};
-}
-
-StatusWithMatchExpression ExtensionsCallbackDisallowExtensions::parseText(BSONElement text) const {
- return {Status(ErrorCodes::NoMatchParseContext, "no context for parsing $text")};
-}
-
-} // namespace mongo
diff --git a/src/mongo/db/matcher/extensions_callback_disallow_extensions.h b/src/mongo/db/matcher/extensions_callback_disallow_extensions.h
deleted file mode 100644
index c641aecd0d1..00000000000
--- a/src/mongo/db/matcher/extensions_callback_disallow_extensions.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * Copyright (C) 2015 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#pragma once
-
-#include "mongo/db/matcher/extensions_callback.h"
-
-namespace mongo {
-
-/**
- * ExtensionsCallbackDisallowExtensions produces an error during parsing if expressions which
- * require context are present. This implementation of ExtensionsCallback should be used if you wish
- * to explicitly ban the use of query language "extensions" such as $text and $where.
- */
-class ExtensionsCallbackDisallowExtensions : public ExtensionsCallback {
-public:
- /**
- * Always returns an error status.
- */
- StatusWithMatchExpression parseText(BSONElement text) const final;
-
- /**
- * Always returns an error status.
- */
- StatusWithMatchExpression parseWhere(BSONElement where) const final;
-};
-
-} // namespace mongo
diff --git a/src/mongo/db/matcher/matcher.cpp b/src/mongo/db/matcher/matcher.cpp
index faf0f6f1170..5648a4f15d5 100644
--- a/src/mongo/db/matcher/matcher.cpp
+++ b/src/mongo/db/matcher/matcher.cpp
@@ -42,11 +42,13 @@
namespace mongo {
Matcher::Matcher(const BSONObj& pattern,
+ const CollatorInterface* collator,
+ const boost::intrusive_ptr<ExpressionContext>& expCtx,
const ExtensionsCallback& extensionsCallback,
- const CollatorInterface* collator)
+ const MatchExpressionParser::AllowedFeatureSet allowedFeatures)
: _pattern(pattern) {
- StatusWithMatchExpression statusWithMatcher =
- MatchExpressionParser::parse(pattern, extensionsCallback, collator);
+ StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse(
+ pattern, collator, expCtx, extensionsCallback, allowedFeatures);
uassert(16810,
mongoutils::str::stream() << "bad query: " << statusWithMatcher.getStatus().toString(),
statusWithMatcher.isOK());
diff --git a/src/mongo/db/matcher/matcher.h b/src/mongo/db/matcher/matcher.h
index e37a6a0a3b5..382b0dd4e0d 100644
--- a/src/mongo/db/matcher/matcher.h
+++ b/src/mongo/db/matcher/matcher.h
@@ -36,6 +36,7 @@
#include "mongo/bson/bsonobj.h"
#include "mongo/db/matcher/expression.h"
#include "mongo/db/matcher/expression_parser.h"
+#include "mongo/db/matcher/extensions_callback_noop.h"
#include "mongo/db/matcher/match_details.h"
@@ -54,8 +55,11 @@ public:
* 'collator' must outlive the returned Matcher and any MatchExpression cloned from it.
*/
explicit Matcher(const BSONObj& pattern,
- const ExtensionsCallback& extensionsCallback,
- const CollatorInterface* collator);
+ const CollatorInterface* collator,
+ const boost::intrusive_ptr<ExpressionContext>& expCtx = nullptr,
+ const ExtensionsCallback& extensionsCallback = ExtensionsCallbackNoop(),
+ MatchExpressionParser::AllowedFeatureSet allowedFeatures =
+ MatchExpressionParser::kBanAllSpecialFeatures);
bool matches(const BSONObj& doc, MatchDetails* details = NULL) const;
diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index_test.cpp b/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index_test.cpp
index a0e0d6573ba..87c0896193a 100644
--- a/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index_test.cpp
+++ b/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index_test.cpp
@@ -31,7 +31,6 @@
#include "mongo/db/jsobj.h"
#include "mongo/db/json.h"
#include "mongo/db/matcher/expression_parser.h"
-#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
#include "mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index.h"
#include "mongo/unittest/unittest.h"
@@ -42,16 +41,14 @@ constexpr CollatorInterface* kSimpleCollator = nullptr;
TEST(InternalSchemaAllElemMatchFromIndexMatchExpression, MatchesEmptyQuery) {
auto query = fromjson("{a: {$_internalSchemaAllElemMatchFromIndex: [2, {}]}}");
- auto expr = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_TRUE(expr.getValue()->matchesBSON(BSON("a" << BSON_ARRAY(1 << 2 << 3 << 4))));
}
TEST(InternalSchemaAllElemMatchFromIndexMatchExpression, MatchesValidQueries) {
auto query = fromjson("{a: {$_internalSchemaAllElemMatchFromIndex: [2, {a: {$lt: 5}}]}}");
- auto expr = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_TRUE(expr.getValue()->matchesBSON(BSON("a" << BSON_ARRAY(1 << 2 << 3 << 4))));
@@ -63,24 +60,21 @@ TEST(InternalSchemaAllElemMatchFromIndexMatchExpression, MatchesValidQueries) {
TEST(InternalSchemaAllElemMatchFromIndexMatchExpression, RejectsNonArrayElements) {
auto query = fromjson("{a: {$_internalSchemaAllElemMatchFromIndex: [2, {a: {$lt: 5}}]}}");
- auto expr = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_FALSE(expr.getValue()->matchesBSON(BSON("a" << BSON("a" << 1))));
}
TEST(InternalSchemaAllElemMatchFromIndexMatchExpression, MatchesArraysWithLessElementsThanIndex) {
auto query = fromjson("{a: {$_internalSchemaAllElemMatchFromIndex: [2, {a: {$lt: 5}}]}}");
- auto expr = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_TRUE(expr.getValue()->matchesBSON(BSON("a" << BSON_ARRAY(1))));
}
TEST(InternalSchemaAllElemMatchFromIndexMatchExpression, NestedArraysMatchSubexpression) {
auto query = fromjson("{a: {$_internalSchemaAllElemMatchFromIndex: [2, {a: {$lt: 5}}]}}");
- auto expr = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_TRUE(
expr.getValue()->matchesBSON(BSON("a" << BSON_ARRAY(1 << 2 << BSON_ARRAY(3 << 4) << 4))));
@@ -92,8 +86,7 @@ TEST(InternalSchemaAllElemMatchFromIndexMatchExpression, NestedArraysMatchSubexp
TEST(InternalSchemaAllElemMatchFromIndexMatchExpression, MatchedQueriesWithDottedPaths) {
auto query = fromjson("{'a.b': {$_internalSchemaAllElemMatchFromIndex: [2, {a: {$lt: 5}}]}}");
- auto expr = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_TRUE(
expr.getValue()->matchesBSON(BSON("a" << BSON("b" << BSON_ARRAY(1 << 2 << 3 << 4)))));
diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties_test.cpp b/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties_test.cpp
index b00d45d9172..e19a5bc2637 100644
--- a/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties_test.cpp
+++ b/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties_test.cpp
@@ -30,7 +30,6 @@
#include "mongo/bson/json.h"
#include "mongo/db/matcher/expression_parser.h"
-#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
#include "mongo/db/matcher/schema/expression_internal_schema_allowed_properties.h"
#include "mongo/unittest/unittest.h"
@@ -41,8 +40,7 @@ TEST(InternalSchemaAllowedPropertiesMatchExpression, MatchesObjectsWithListedPro
auto filter = fromjson(
"{$_internalSchemaAllowedProperties: {properties: ['a', 'b'],"
"namePlaceholder: 'i', patternProperties: [], otherwise: {i: 0}}}");
- auto expr = MatchExpressionParser::parse(
- filter, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(filter, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_TRUE(expr.getValue()->matchesBSON(fromjson("{a: 1, b: 1}")));
@@ -61,8 +59,7 @@ TEST(InternalSchemaAllowedPropertiesMatchExpression, MatchesObjectsWithMatchingP
],
otherwise: {i: {$type: 'string'}}
}})");
- auto expr = MatchExpressionParser::parse(
- filter, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(filter, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_TRUE(expr.getValue()->matchesBSON(fromjson("{puppies: 2, kittens: 3, phoneNum: 1234}")));
@@ -75,8 +72,7 @@ TEST(InternalSchemaAllowedPropertiesMatchExpression,
auto filter = fromjson(
"{$_internalSchemaAllowedProperties: {properties: ['a'], namePlaceholder: 'a',"
"patternProperties: [{regex: /a/, expression: {a: {$gt: 5}}}], otherwise: {a: 0}}}");
- auto expr = MatchExpressionParser::parse(
- filter, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(filter, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_TRUE(expr.getValue()->matchesBSON(fromjson("{a: 6}")));
@@ -95,8 +91,7 @@ TEST(InternalSchemaAllowedPropertiesMatchExpression, OtherwiseEnforcedWhenApprop
],
otherwise: {i: {$type: 'string'}}
}})");
- auto expr = MatchExpressionParser::parse(
- filter, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(filter, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_TRUE(expr.getValue()->matchesBSON(fromjson("{foo: 'bar'}")));
@@ -107,8 +102,7 @@ TEST(InternalSchemaAllowedPropertiesMatchExpression, EquivalentToClone) {
auto filter = fromjson(
"{$_internalSchemaAllowedProperties: {properties: ['a'], namePlaceholder: 'i',"
"patternProperties: [{regex: /a/, expression: {i: 1}}], otherwise: {i: 7}}}");
- auto expr = MatchExpressionParser::parse(
- filter, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(filter, kSimpleCollator);
ASSERT_OK(expr.getStatus());
auto clone = expr.getValue()->shallowClone();
ASSERT_TRUE(expr.getValue()->equivalent(clone.get()));
diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_cond_test.cpp b/src/mongo/db/matcher/schema/expression_internal_schema_cond_test.cpp
index d8a1dc63871..b1cbb03d18a 100644
--- a/src/mongo/db/matcher/schema/expression_internal_schema_cond_test.cpp
+++ b/src/mongo/db/matcher/schema/expression_internal_schema_cond_test.cpp
@@ -30,7 +30,6 @@
#include "mongo/bson/json.h"
#include "mongo/db/matcher/expression_parser.h"
-#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
#include "mongo/db/matcher/schema/expression_internal_schema_cond.h"
#include "mongo/db/matcher/schema/expression_internal_schema_object_match.h"
#include "mongo/unittest/unittest.h"
@@ -46,14 +45,11 @@ std::unique_ptr<InternalSchemaCondMatchExpression> createCondMatchExpression(BSO
auto cond = stdx::make_unique<InternalSchemaCondMatchExpression>();
const CollatorInterface* kSimpleCollator = nullptr;
- auto conditionExpr = MatchExpressionParser::parse(
- condition, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto conditionExpr = MatchExpressionParser::parse(condition, kSimpleCollator);
ASSERT_OK(conditionExpr.getStatus());
- auto thenBranchExpr = MatchExpressionParser::parse(
- thenBranch, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto thenBranchExpr = MatchExpressionParser::parse(thenBranch, kSimpleCollator);
ASSERT_OK(thenBranchExpr.getStatus());
- auto elseBranchExpr = MatchExpressionParser::parse(
- elseBranch, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto elseBranchExpr = MatchExpressionParser::parse(elseBranch, kSimpleCollator);
cond->init({{std::move(conditionExpr.getValue()),
std::move(thenBranchExpr.getValue()),
diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index_test.cpp b/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index_test.cpp
index 0f6dc702287..87c1d847beb 100644
--- a/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index_test.cpp
+++ b/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index_test.cpp
@@ -31,7 +31,6 @@
#include "mongo/bson/json.h"
#include "mongo/db/matcher/expression_parser.h"
#include "mongo/db/matcher/expression_with_placeholder.h"
-#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
#include "mongo/db/matcher/schema/expression_internal_schema_match_array_index.h"
#include "mongo/db/query/collation/collator_interface_mock.h"
#include "mongo/unittest/unittest.h"
@@ -44,8 +43,7 @@ TEST(InternalSchemaMatchArrayIndexMatchExpression, RejectsNonArrays) {
auto filter = fromjson(
"{foo: {$_internalSchemaMatchArrayIndex:"
"{index: 0, namePlaceholder: 'i', expression: {i: {$gt: 7}}}}}");
- auto expr = MatchExpressionParser::parse(
- filter, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(filter, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_FALSE(expr.getValue()->matchesBSON(fromjson("{foo: 'blah'}")));
ASSERT_FALSE(expr.getValue()->matchesBSON(fromjson("{foo: 7}")));
@@ -56,8 +54,7 @@ TEST(InternalSchemaMatchArrayIndexMatchExpression, MatchesArraysWithMatchingElem
auto filter = fromjson(
"{foo: {$_internalSchemaMatchArrayIndex:"
"{index: 0, namePlaceholder: 'i', expression: {i: {$elemMatch: {'bar': 7}}}}}}");
- auto expr = MatchExpressionParser::parse(
- filter, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(filter, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_TRUE(expr.getValue()->matchesBSON(fromjson("{foo: [[{bar: 7}], [{bar: 5}]]}")));
ASSERT_TRUE(expr.getValue()->matchesBSON(fromjson("{foo: [[{bar: [3, 5, 7]}], [{bar: 5}]]}")));
@@ -65,8 +62,7 @@ TEST(InternalSchemaMatchArrayIndexMatchExpression, MatchesArraysWithMatchingElem
filter = fromjson(
"{baz: {$_internalSchemaMatchArrayIndex:"
"{index: 2, namePlaceholder: 'i', expression: {i: {$type: 'string'}}}}}");
- expr = MatchExpressionParser::parse(
- filter, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ expr = MatchExpressionParser::parse(filter, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_TRUE(expr.getValue()->matchesBSON(fromjson("{baz: [0, 1, '2']}")));
}
@@ -75,16 +71,14 @@ TEST(InternalSchemaMatchArrayIndexMatchExpression, DoesNotMatchArrayIfMatchingEl
auto filter = fromjson(
"{foo: {$_internalSchemaMatchArrayIndex:"
"{index: 0, namePlaceholder: 'i', expression: {i: {$lte: 7}}}}}");
- auto expr = MatchExpressionParser::parse(
- filter, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(filter, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_FALSE(expr.getValue()->matchesBSON(fromjson("{foo: [33, 0, 1, 2]}")));
filter = fromjson(
"{foo: {$_internalSchemaMatchArrayIndex:"
"{index: 1, namePlaceholder: 'i', expression: {i: {$lte: 7}}}}}");
- expr = MatchExpressionParser::parse(
- filter, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ expr = MatchExpressionParser::parse(filter, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_FALSE(expr.getValue()->matchesBSON(fromjson("{foo: [0, 99, 1, 2]}")));
}
@@ -93,16 +87,14 @@ TEST(InternalSchemaMatchArrayIndexMatchExpression, MatchesIfNotEnoughArrayElemen
auto filter = fromjson(
"{foo: {$_internalSchemaMatchArrayIndex:"
"{index: 0, namePlaceholder: 'i', expression: {i: 1}}}}");
- auto expr = MatchExpressionParser::parse(
- filter, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(filter, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_TRUE(expr.getValue()->matchesBSON(fromjson("{foo: []}")));
filter = fromjson(
"{foo: {$_internalSchemaMatchArrayIndex:"
"{index: 4, namePlaceholder: 'i', expression: {i: 1}}}}");
- expr = MatchExpressionParser::parse(
- filter, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ expr = MatchExpressionParser::parse(filter, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_TRUE(expr.getValue()->matchesBSON(fromjson("{foo: ['no', 'no', 'no', 'no']}")));
}
@@ -111,8 +103,7 @@ TEST(InternalSchemaMatchArrayIndexMatchExpression, EquivalentToClone) {
auto filter = fromjson(
"{foo: {$_internalSchemaMatchArrayIndex:"
"{index: 0, namePlaceholder: 'i', expression: {i: {$type: 'number'}}}}}");
- auto expr = MatchExpressionParser::parse(
- filter, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(filter, kSimpleCollator);
ASSERT_OK(expr.getStatus());
auto clone = expr.getValue()->shallowClone();
ASSERT_TRUE(expr.getValue()->equivalent(clone.get()));
diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_object_match_test.cpp b/src/mongo/db/matcher/schema/expression_internal_schema_object_match_test.cpp
index 89a95e7eff3..d195b901af6 100644
--- a/src/mongo/db/matcher/schema/expression_internal_schema_object_match_test.cpp
+++ b/src/mongo/db/matcher/schema/expression_internal_schema_object_match_test.cpp
@@ -29,7 +29,6 @@
#include "mongo/db/json.h"
#include "mongo/db/matcher/expression_parser.h"
-#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
#include "mongo/db/matcher/matcher.h"
#include "mongo/db/matcher/schema/expression_internal_schema_object_match.h"
#include "mongo/db/query/collation/collator_interface_mock.h"
@@ -40,8 +39,7 @@ namespace mongo {
namespace {
TEST(InternalSchemaObjectMatchExpression, RejectsNonObjectElements) {
- auto subExpr = MatchExpressionParser::parse(
- BSON("b" << 1), ExtensionsCallbackDisallowExtensions(), nullptr);
+ auto subExpr = MatchExpressionParser::parse(BSON("b" << 1), nullptr);
ASSERT_OK(subExpr.getStatus());
InternalSchemaObjectMatchExpression objMatch;
@@ -56,7 +54,6 @@ TEST(InternalSchemaObjectMatchExpression, RejectsNonObjectElements) {
TEST(InternalSchemaObjectMatchExpression, RejectsObjectsThatDontMatch) {
auto subExpr = MatchExpressionParser::parse(BSON("b" << BSON("$type"
<< "string")),
- ExtensionsCallbackDisallowExtensions(),
nullptr);
ASSERT_OK(subExpr.getStatus());
@@ -70,7 +67,6 @@ TEST(InternalSchemaObjectMatchExpression, RejectsObjectsThatDontMatch) {
TEST(InternalSchemaObjectMatchExpression, AcceptsObjectsThatMatch) {
auto subExpr = MatchExpressionParser::parse(BSON("b" << BSON("$type"
<< "string")),
- ExtensionsCallbackDisallowExtensions(),
nullptr);
ASSERT_OK(subExpr.getStatus());
@@ -92,7 +88,6 @@ TEST(InternalSchemaObjectMatchExpression, AcceptsObjectsThatMatch) {
TEST(InternalSchemaObjectMatchExpression, DottedPathAcceptsObjectsThatMatch) {
auto subExpr = MatchExpressionParser::parse(BSON("b.c.d" << BSON("$type"
<< "string")),
- ExtensionsCallbackDisallowExtensions(),
nullptr);
ASSERT_OK(subExpr.getStatus());
@@ -107,8 +102,7 @@ TEST(InternalSchemaObjectMatchExpression, DottedPathAcceptsObjectsThatMatch) {
}
TEST(InternalSchemaObjectMatchExpression, EmptyMatchAcceptsAllObjects) {
- auto subExpr =
- MatchExpressionParser::parse(BSONObj(), ExtensionsCallbackDisallowExtensions(), nullptr);
+ auto subExpr = MatchExpressionParser::parse(BSONObj(), nullptr);
ASSERT_OK(subExpr.getStatus());
InternalSchemaObjectMatchExpression objMatch;
@@ -130,8 +124,7 @@ TEST(InternalSchemaObjectMatchExpression, NestedObjectMatchReturnsCorrectPath) {
" $or: [{c: {$type: 'string'}}, {c: {$gt: 0}}]"
" }}}"
" }}}");
- auto objMatch =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), nullptr);
+ auto objMatch = MatchExpressionParser::parse(query, nullptr);
ASSERT_OK(objMatch.getStatus());
ASSERT_EQ(objMatch.getValue()->path(), "a");
@@ -145,8 +138,7 @@ TEST(InternalSchemaObjectMatchExpression, MatchesNestedObjectMatch) {
" c: 3"
" }}}"
" }}}");
- auto objMatch =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), nullptr);
+ auto objMatch = MatchExpressionParser::parse(query, nullptr);
ASSERT_OK(objMatch.getStatus());
ASSERT_FALSE(objMatch.getValue()->matchesBSON(fromjson("{a: 1}")));
@@ -160,20 +152,20 @@ TEST(InternalSchemaObjectMatchExpression, EquivalentReturnsCorrectResults) {
" {a: {$_internalSchemaObjectMatch: {"
" b: 3"
" }}}");
- Matcher objectMatch(query, ExtensionsCallbackDisallowExtensions(), nullptr);
+ Matcher objectMatch(query, nullptr);
query = fromjson(
" {a: {$_internalSchemaObjectMatch: {"
" b: {$eq: 3}"
" }}}");
- Matcher objectMatchEq(query, ExtensionsCallbackDisallowExtensions(), nullptr);
+ Matcher objectMatchEq(query, nullptr);
ASSERT_TRUE(objectMatch.getMatchExpression()->equivalent(objectMatchEq.getMatchExpression()));
query = fromjson(
" {a: {$_internalSchemaObjectMatch: {"
" c: {$eq: 3}"
" }}}");
- Matcher objectMatchNotEq(query, ExtensionsCallbackDisallowExtensions(), nullptr);
+ Matcher objectMatchNotEq(query, nullptr);
ASSERT_FALSE(
objectMatch.getMatchExpression()->equivalent(objectMatchNotEq.getMatchExpression()));
}
@@ -184,8 +176,7 @@ TEST(InternalSchemaObjectMatchExpression, SubExpressionRespectsCollator) {
"{a: {$_internalSchemaObjectMatch: {"
" b: {$eq: 'FOO'}"
"}}}");
- auto objectMatch =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator);
+ auto objectMatch = MatchExpressionParser::parse(query, &collator);
ASSERT_OK(objectMatch.getStatus());
ASSERT_TRUE(objectMatch.getValue()->matchesBSON(fromjson("{a: {b: 'FOO'}}")));
@@ -195,8 +186,7 @@ TEST(InternalSchemaObjectMatchExpression, SubExpressionRespectsCollator) {
TEST(InternalSchemaObjectMatchExpression, RejectsArraysContainingMatchingSubObject) {
auto query = fromjson("{a: {$_internalSchemaObjectMatch: {b: 1}}}");
- auto objMatch =
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), nullptr);
+ auto objMatch = MatchExpressionParser::parse(query, nullptr);
ASSERT_OK(objMatch.getStatus());
ASSERT_FALSE(objMatch.getValue()->matchesBSON(fromjson("{a: 1}")));
diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_xor_test.cpp b/src/mongo/db/matcher/schema/expression_internal_schema_xor_test.cpp
index 2e2efe50327..37f6ff4f6c2 100644
--- a/src/mongo/db/matcher/schema/expression_internal_schema_xor_test.cpp
+++ b/src/mongo/db/matcher/schema/expression_internal_schema_xor_test.cpp
@@ -33,7 +33,6 @@
#include "mongo/db/matcher/expression.h"
#include "mongo/db/matcher/expression_leaf.h"
#include "mongo/db/matcher/expression_parser.h"
-#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
#include "mongo/db/matcher/schema/expression_internal_schema_xor.h"
#include "mongo/unittest/unittest.h"
@@ -50,8 +49,7 @@ TEST(InternalSchemaXorOp, MatchesNothingWhenHasNoClauses) {
TEST(InternalSchemaXorOp, MatchesSingleClause) {
BSONObj matchPredicate = fromjson("{$_internalSchemaXor: [{a: { $ne: 5 }}]}");
const CollatorInterface* collator = nullptr;
- auto expr = MatchExpressionParser::parse(
- matchPredicate, ExtensionsCallbackDisallowExtensions(), collator);
+ auto expr = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(expr.getStatus());
ASSERT_TRUE(expr.getValue()->matchesBSON(BSON("a" << 4)));
@@ -65,8 +63,7 @@ TEST(InternalSchemaXorOp, MatchesThreeClauses) {
BSONObj matchPredicate =
fromjson("{$_internalSchemaXor: [{a: { $gt: 10 }}, {a: { $lt: 0 }}, {b: 0}]}");
- auto expr = MatchExpressionParser::parse(
- matchPredicate, ExtensionsCallbackDisallowExtensions(), collator);
+ auto expr = MatchExpressionParser::parse(matchPredicate, collator);
ASSERT_OK(expr.getStatus());
ASSERT_TRUE(expr.getValue()->matchesBSON(BSON("a" << -1)));
@@ -84,8 +81,7 @@ TEST(InternalSchemaXorOp, DoesNotUseElemMatchKey) {
BSONObj matchPredicate = fromjson("{$_internalSchemaXor: [{a: 1}, {b: 2}]}");
- auto expr = MatchExpressionParser::parse(
- matchPredicate, ExtensionsCallbackDisallowExtensions(), collator);
+ auto expr = MatchExpressionParser::parse(matchPredicate, collator);
MatchDetails details;
details.requestElemMatchKey();
ASSERT_OK(expr.getStatus());
diff --git a/src/mongo/db/matcher/schema/expression_parser_schema_test.cpp b/src/mongo/db/matcher/schema/expression_parser_schema_test.cpp
index 74bded78933..af86c2928eb 100644
--- a/src/mongo/db/matcher/schema/expression_parser_schema_test.cpp
+++ b/src/mongo/db/matcher/schema/expression_parser_schema_test.cpp
@@ -32,7 +32,6 @@
#include "mongo/db/matcher/expression.h"
#include "mongo/db/matcher/expression_parser.h"
#include "mongo/db/matcher/expression_type.h"
-#include "mongo/db/matcher/extensions_callback_disallow_extensions.h"
#include "mongo/db/matcher/schema/expression_internal_schema_max_items.h"
#include "mongo/db/matcher/schema/expression_internal_schema_max_length.h"
#include "mongo/db/matcher/schema/expression_internal_schema_min_items.h"
@@ -49,8 +48,7 @@ constexpr CollatorInterface* kSimpleCollator = nullptr;
TEST(MatchExpressionParserSchemaTest, MinItemsCorrectlyParsesIntegerArgument) {
BSONObj query = BSON("x" << BSON("$_internalSchemaMinItems" << 2));
- StatusWithMatchExpression result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -61,8 +59,7 @@ TEST(MatchExpressionParserSchemaTest, MinItemsCorrectlyParsesIntegerArgument) {
TEST(MatchExpressionParserSchemaTest, MinItemsCorrectlyParsesLongArgument) {
BSONObj query = BSON("x" << BSON("$_internalSchemaMinItems" << 2LL));
- StatusWithMatchExpression result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -73,8 +70,7 @@ TEST(MatchExpressionParserSchemaTest, MinItemsCorrectlyParsesLongArgument) {
TEST(MatchExpressionParserSchemaTest, MinItemsCorrectlyParsesDoubleArgumentAsInteger) {
BSONObj query = BSON("x" << BSON("$_internalSchemaMinItems" << 2.0));
- StatusWithMatchExpression result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -85,8 +81,7 @@ TEST(MatchExpressionParserSchemaTest, MinItemsCorrectlyParsesDoubleArgumentAsInt
TEST(MatchExpressionParserSchemaTest, MinItemsCorrectlyParsesDecimalArgumentAsInteger) {
BSONObj query = BSON("x" << BSON("$_internalSchemaMinItems" << Decimal128("2")));
- StatusWithMatchExpression result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -97,8 +92,7 @@ TEST(MatchExpressionParserSchemaTest, MinItemsCorrectlyParsesDecimalArgumentAsIn
TEST(MatchExpressionParserSchemaTest, MaxItemsCorrectlyParsesIntegerArgument) {
BSONObj query = BSON("x" << BSON("$_internalSchemaMaxItems" << 2));
- StatusWithMatchExpression result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -109,8 +103,7 @@ TEST(MatchExpressionParserSchemaTest, MaxItemsCorrectlyParsesIntegerArgument) {
TEST(MatchExpressionParserSchemaTest, MaxItemsCorrectlyParsesLongArgument) {
BSONObj query = BSON("x" << BSON("$_internalSchemaMaxItems" << 2LL));
- StatusWithMatchExpression result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -122,8 +115,7 @@ TEST(MatchExpressionParserSchemaTest, MaxItemsCorrectlyParsesLongArgument) {
TEST(MatchExpressionParserSchemaTest, MaxItemsCorrectlyParsesDoubleArgumentAsInteger) {
BSONObj query = BSON("x" << BSON("$_internalSchemaMaxItems" << 2.0));
- StatusWithMatchExpression result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -134,8 +126,7 @@ TEST(MatchExpressionParserSchemaTest, MaxItemsCorrectlyParsesDoubleArgumentAsInt
TEST(MatchExpressionParserSchemaTest, MaxItemsCorrectlyParsesDecimalArgumentAsInteger) {
BSONObj query = BSON("x" << BSON("$_internalSchemaMaxItems" << Decimal128("2")));
- StatusWithMatchExpression result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1)));
@@ -146,31 +137,26 @@ TEST(MatchExpressionParserSchemaTest, MaxItemsCorrectlyParsesDecimalArgumentAsIn
TEST(MatchExpressionParserSchemaTest, UniqueItemsFailsToParseNonTrueArguments) {
auto queryIntArgument = BSON("x" << BSON("$_internalSchemaUniqueItems" << 0));
- auto expr = MatchExpressionParser::parse(
- queryIntArgument, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(queryIntArgument, kSimpleCollator);
ASSERT_EQ(expr.getStatus(), ErrorCodes::FailedToParse);
auto queryStringArgument = BSON("x" << BSON("$_internalSchemaUniqueItems"
<< ""));
- expr = MatchExpressionParser::parse(
- queryStringArgument, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ expr = MatchExpressionParser::parse(queryStringArgument, kSimpleCollator);
ASSERT_EQ(expr.getStatus(), ErrorCodes::FailedToParse);
auto queryDoubleArgument = BSON("x" << BSON("$_internalSchemaUniqueItems" << 1.0));
- expr = MatchExpressionParser::parse(
- queryDoubleArgument, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ expr = MatchExpressionParser::parse(queryDoubleArgument, kSimpleCollator);
ASSERT_EQ(expr.getStatus(), ErrorCodes::FailedToParse);
auto queryFalseArgument = BSON("x" << BSON("$_internalSchemaUniqueItems" << false));
- expr = MatchExpressionParser::parse(
- queryFalseArgument, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ expr = MatchExpressionParser::parse(queryFalseArgument, kSimpleCollator);
ASSERT_EQ(expr.getStatus(), ErrorCodes::FailedToParse);
}
TEST(MatchExpressionParserSchemaTest, UniqueItemsParsesTrueBooleanArgument) {
auto query = BSON("x" << BSON("$_internalSchemaUniqueItems" << true));
- auto expr = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_FALSE(expr.getValue()->matchesBSON(fromjson("{x: 1}")));
@@ -184,20 +170,17 @@ TEST(MatchExpressionParserSchemaTest, UniqueItemsParsesTrueBooleanArgument) {
TEST(MatchExpressionParserSchemaTest, ObjectMatchOnlyAcceptsAnObjectArgument) {
auto query = BSON("a" << BSON("$_internalSchemaObjectMatch" << 1));
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_EQ(result.getStatus(), ErrorCodes::FailedToParse);
query = BSON("a" << BSON("$_internalSchemaObjectMatch"
<< "string"));
- result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_EQ(result.getStatus(), ErrorCodes::FailedToParse);
query = BSON(
"a" << BSON("$_internalSchemaObjectMatch" << BSON_ARRAY(BSON("a" << 1) << BSON("b" << 1))));
- result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_EQ(result.getStatus(), ErrorCodes::FailedToParse);
}
@@ -207,8 +190,7 @@ TEST(MatchExpressionParserSchemaTest, ObjectMatchCorrectlyParsesObjects) {
" b: {$gte: 0}"
" }}"
"}");
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_TRUE(result.isOK());
ASSERT_FALSE(result.getValue()->matchesBSON(fromjson("{a: 1}")));
@@ -225,8 +207,7 @@ TEST(MatchExpressionParserSchemaTest, ObjectMatchCorrectlyParsesNestedObjectMatc
" $or: [{c: {$type: 'string'}}, {c: {$gt: 0}}]"
" }}"
"}}}");
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_TRUE(result.isOK());
ASSERT_FALSE(result.getValue()->matchesBSON(fromjson("{a: 1}")));
@@ -243,8 +224,7 @@ TEST(MatchExpressionParserSchemaTest, ObjectMatchSubExprRejectsTopLevelOperators
"{a: {$_internalSchemaObjectMatch: {"
" $isolated: 1"
"}}}");
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_EQ(result.getStatus(), ErrorCodes::BadValue);
}
@@ -253,8 +233,7 @@ TEST(MatchExpressionParserSchemaTest, ObjectMatchSubExprRejectsTopLevelOperators
//
TEST(MatchExpressionParserSchemaTest, MinLengthCorrectlyParsesIntegerArgument) {
BSONObj query = BSON("x" << BSON("$_internalSchemaMinLength" << 2));
- StatusWithMatchExpression result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(result.getStatus());
ASSERT(!result.getValue()->matchesBSON(BSON("x"
@@ -267,8 +246,7 @@ TEST(MatchExpressionParserSchemaTest, MinLengthCorrectlyParsesIntegerArgument) {
TEST(MatchExpressionParserSchemaTest, MinLengthCorrectlyParsesLongArgument) {
BSONObj query = BSON("x" << BSON("$_internalSchemaMinLength" << 2LL));
- StatusWithMatchExpression result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(result.getStatus());
ASSERT(!result.getValue()->matchesBSON(BSON("x"
@@ -281,8 +259,7 @@ TEST(MatchExpressionParserSchemaTest, MinLengthCorrectlyParsesLongArgument) {
TEST(MatchExpressionParserSchemaTest, MinLengthCorrectlyParsesDoubleArgumentAsInteger) {
BSONObj query = BSON("x" << BSON("$_internalSchemaMinLength" << 2.0));
- StatusWithMatchExpression result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(result.getStatus());
ASSERT(!result.getValue()->matchesBSON(BSON("x"
@@ -295,8 +272,7 @@ TEST(MatchExpressionParserSchemaTest, MinLengthCorrectlyParsesDoubleArgumentAsIn
TEST(MatchExpressionParserSchemaTest, MinLengthCorrectlyParsesDecimalArgumentAsInteger) {
BSONObj query = BSON("x" << BSON("$_internalSchemaMinLength" << Decimal128("2")));
- StatusWithMatchExpression result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(result.getStatus());
ASSERT(!result.getValue()->matchesBSON(BSON("x"
@@ -310,29 +286,24 @@ TEST(MatchExpressionParserSchemaTest, MinLengthCorrectlyParsesDecimalArgumentAsI
TEST(MatchExpressionParserSchemaTest, MinLengthFailsToParseNonIntegerArguments) {
auto queryStringArgument = BSON("x" << BSON("$_internalSchemaMinLength"
<< "abc"));
- auto expr = MatchExpressionParser::parse(
- queryStringArgument, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(queryStringArgument, kSimpleCollator);
ASSERT_NOT_OK(expr.getStatus());
auto queryEmptyStringArgument = BSON("x" << BSON("$_internalSchemaMinLength"
<< ""));
- expr = MatchExpressionParser::parse(
- queryEmptyStringArgument, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ expr = MatchExpressionParser::parse(queryEmptyStringArgument, kSimpleCollator);
ASSERT_NOT_OK(expr.getStatus());
auto queryDoubleArgument = BSON("x" << BSON("$_internalSchemaMinLength" << 1.5));
- expr = MatchExpressionParser::parse(
- queryDoubleArgument, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ expr = MatchExpressionParser::parse(queryDoubleArgument, kSimpleCollator);
ASSERT_NOT_OK(expr.getStatus());
auto queryFalseArgument = BSON("x" << BSON("$_internalSchemaMinLength" << false));
- expr = MatchExpressionParser::parse(
- queryFalseArgument, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ expr = MatchExpressionParser::parse(queryFalseArgument, kSimpleCollator);
ASSERT_NOT_OK(expr.getStatus());
auto queryArrArgument = BSON("x" << BSON("$_internalSchemaMinLength" << BSON_ARRAY(1)));
- expr = MatchExpressionParser::parse(
- queryArrArgument, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ expr = MatchExpressionParser::parse(queryArrArgument, kSimpleCollator);
ASSERT_NOT_OK(expr.getStatus());
}
@@ -341,8 +312,7 @@ TEST(MatchExpressionParserSchemaTest, MinLengthFailsToParseNonIntegerArguments)
//
TEST(MatchExpressionParserSchemaTest, MaxLengthCorrectlyParsesIntegerArgument) {
BSONObj query = BSON("x" << BSON("$_internalSchemaMaxLength" << 2));
- StatusWithMatchExpression result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(result.getStatus());
ASSERT(result.getValue()->matchesBSON(BSON("x"
@@ -355,8 +325,7 @@ TEST(MatchExpressionParserSchemaTest, MaxLengthCorrectlyParsesIntegerArgument) {
TEST(MatchExpressionParserSchemaTest, MaxLengthCorrectlyParsesLongArgument) {
BSONObj query = BSON("x" << BSON("$_internalSchemaMaxLength" << 2LL));
- StatusWithMatchExpression result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(result.getStatus());
ASSERT(result.getValue()->matchesBSON(BSON("x"
@@ -369,8 +338,7 @@ TEST(MatchExpressionParserSchemaTest, MaxLengthCorrectlyParsesLongArgument) {
TEST(MatchExpressionParserSchemaTest, MaxLengthCorrectlyParsesDoubleArgumentAsInteger) {
BSONObj query = BSON("x" << BSON("$_internalSchemaMaxLength" << 2.0));
- StatusWithMatchExpression result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(result.getStatus());
ASSERT(result.getValue()->matchesBSON(BSON("x"
@@ -383,8 +351,7 @@ TEST(MatchExpressionParserSchemaTest, MaxLengthCorrectlyParsesDoubleArgumentAsIn
TEST(MatchExpressionParserSchemaTest, MaxLengthorrectlyParsesDecimalArgumentAsInteger) {
BSONObj query = BSON("x" << BSON("$_internalSchemaMaxLength" << Decimal128("2")));
- StatusWithMatchExpression result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ StatusWithMatchExpression result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(result.getStatus());
ASSERT(result.getValue()->matchesBSON(BSON("x"
@@ -398,80 +365,62 @@ TEST(MatchExpressionParserSchemaTest, MaxLengthorrectlyParsesDecimalArgumentAsIn
TEST(MatchExpressionParserSchemaTest, MaxLengthFailsToParseNonIntegerArguments) {
auto queryStringArgument = BSON("x" << BSON("$_internalSchemaMaxLength"
<< "abc"));
- auto expr = MatchExpressionParser::parse(
- queryStringArgument, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(queryStringArgument, kSimpleCollator);
ASSERT_NOT_OK(expr.getStatus());
auto queryEmptyStringArgument = BSON("x" << BSON("$_internalSchemaMaxLength"
<< ""));
- expr = MatchExpressionParser::parse(
- queryEmptyStringArgument, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ expr = MatchExpressionParser::parse(queryEmptyStringArgument, kSimpleCollator);
ASSERT_NOT_OK(expr.getStatus());
auto queryDoubleArgument = BSON("x" << BSON("$_internalSchemaMaxLength" << 1.5));
- expr = MatchExpressionParser::parse(
- queryDoubleArgument, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ expr = MatchExpressionParser::parse(queryDoubleArgument, kSimpleCollator);
ASSERT_NOT_OK(expr.getStatus());
auto queryFalseArgument = BSON("x" << BSON("$_internalSchemaMaxLength" << false));
- expr = MatchExpressionParser::parse(
- queryFalseArgument, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ expr = MatchExpressionParser::parse(queryFalseArgument, kSimpleCollator);
ASSERT_NOT_OK(expr.getStatus());
auto queryArrArgument = BSON("x" << BSON("$_internalSchemaMaxLength" << BSON_ARRAY(1)));
- expr = MatchExpressionParser::parse(
- queryArrArgument, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ expr = MatchExpressionParser::parse(queryArrArgument, kSimpleCollator);
ASSERT_NOT_OK(expr.getStatus());
}
TEST(MatchExpressionParserSchemaTest, CondFailsToParseNonObjectArguments) {
auto queryWithInteger = fromjson("{$_internalSchemaCond: [1, {foo: 'bar'}, {baz: 7}]}");
ASSERT_EQ(ErrorCodes::FailedToParse,
- MatchExpressionParser::parse(
- queryWithInteger, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus());
+ MatchExpressionParser::parse(queryWithInteger, kSimpleCollator).getStatus());
auto queryWithArray = fromjson("{$_internalSchemaCond: [{foo: 'bar'}, [{qux: 3}], {baz: 7}]}");
ASSERT_EQ(ErrorCodes::FailedToParse,
- MatchExpressionParser::parse(
- queryWithArray, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus());
+ MatchExpressionParser::parse(queryWithArray, kSimpleCollator).getStatus());
auto queryWithString = fromjson("{$_internalSchemaCond: [{foo: 'bar'}, {baz: 7}, 'blah']}");
ASSERT_EQ(ErrorCodes::FailedToParse,
- MatchExpressionParser::parse(
- queryWithString, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus());
+ MatchExpressionParser::parse(queryWithString, kSimpleCollator).getStatus());
}
TEST(MatchExpressionParserSchemaTest, CondFailsToParseIfNotExactlyThreeArguments) {
auto queryNoArguments = fromjson("{$_internalSchemaCond: []}");
ASSERT_EQ(ErrorCodes::FailedToParse,
- MatchExpressionParser::parse(
- queryNoArguments, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus());
+ MatchExpressionParser::parse(queryNoArguments, kSimpleCollator).getStatus());
auto queryOneArgument = fromjson("{$_internalSchemaCond: [{height: 171}]}");
ASSERT_EQ(ErrorCodes::FailedToParse,
- MatchExpressionParser::parse(
- queryOneArgument, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus());
+ MatchExpressionParser::parse(queryOneArgument, kSimpleCollator).getStatus());
auto queryFourArguments = fromjson(
"{$_internalSchemaCond: [{make: 'lamborghini'}, {model: 'ghost'}, {color: 'celadon'}, "
"{used: false}]}");
ASSERT_EQ(ErrorCodes::FailedToParse,
- MatchExpressionParser::parse(
- queryFourArguments, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus());
+ MatchExpressionParser::parse(queryFourArguments, kSimpleCollator).getStatus());
}
TEST(MatchExpressionParserSchemaTest, CondParsesThreeMatchExpresssions) {
auto query = fromjson(
"{$_internalSchemaCond: [{climate: 'rainy'}, {clothing: 'jacket'}, {clothing: 'shirt'}]}");
- auto expr = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_TRUE(expr.getValue()->matchesBSON(
@@ -485,102 +434,79 @@ TEST(MatchExpressionParserSchemaTest, CondParsesThreeMatchExpresssions) {
TEST(MatchExpressionParserSchemaTest, MatchArrayIndexFailsToParseNonObjectArguments) {
auto query = fromjson("{foo: {$_internalSchemaMatchArrayIndex: 7}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::TypeMismatch);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::TypeMismatch);
query = fromjson("{foo: {$_internalSchemaMatchArrayIndex: []}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::TypeMismatch);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::TypeMismatch);
query = fromjson(
"{foo: {$_internalSchemaMatchArrayIndex:"
"[{index: 5, namePlaceholder: 'i', expression: {i: 1}}]}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::TypeMismatch);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::TypeMismatch);
}
TEST(MatchExpressionParserSchemaTest, MatchArrayIndexFailsToParseIfPlaceholderNotValid) {
auto query = fromjson(
"{foo: {$_internalSchemaMatchArrayIndex:"
"{index: 5, namePlaceholder: 7, expression: {i: 1}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::TypeMismatch);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::TypeMismatch);
query = fromjson(
"{foo: {$_internalSchemaMatchArrayIndex:"
"{index: 5, namePlaceholder: 'Z', expression: {i: 1}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::FailedToParse);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::FailedToParse);
}
TEST(MatchExpressionParserSchemaTest, MatchArrayIndexFailsToParseIfIndexNotANonnegativeInteger) {
auto query = fromjson(
"{foo: {$_internalSchemaMatchArrayIndex:"
"{index: 'blah', namePlaceholder: 'i', expression: {i: 1}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::FailedToParse);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::FailedToParse);
query = fromjson(
"{foo: {$_internalSchemaMatchArrayIndex:"
"{index: -1, namePlaceholder: 'i', expression: {i: 1}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::FailedToParse);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::FailedToParse);
query = fromjson(
"{foo: {$_internalSchemaMatchArrayIndex:"
"{index: 3.14, namePlaceholder: 'i', expression: {i: 1}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::FailedToParse);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::FailedToParse);
}
TEST(MatchExpressionParserSchemaTest, MatchArrayIndexFailsToParseIfExpressionNotValid) {
auto query = fromjson(
"{foo: {$_internalSchemaMatchArrayIndex:"
"{index: 0, namePlaceholder: 'i', expression: 'blah'}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::TypeMismatch);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::TypeMismatch);
query = fromjson(
"{foo: {$_internalSchemaMatchArrayIndex:"
"{index: 0, namePlaceholder: 'i', expression: {doesntMatchThePlaceholder: 7}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::FailedToParse);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::FailedToParse);
query = fromjson(
"{foo: {$_internalSchemaMatchArrayIndex:"
"{index: 0, namePlaceholder: 'i', expression: {$invalid: 'blah'}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::BadValue);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::BadValue);
}
TEST(MatchExpressionParserSchemaTest, MatchArrayIndexParsesSuccessfully) {
auto query = fromjson(
"{foo: {$_internalSchemaMatchArrayIndex:"
"{index: 0, namePlaceholder: 'i', expression: {i: {$lt: 0}}}}}");
- auto matchArrayIndex = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto matchArrayIndex = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(matchArrayIndex.getStatus());
ASSERT_TRUE(matchArrayIndex.getValue()->matchesBSON(fromjson("{foo: [-1, 0, 1]}")));
@@ -591,37 +517,32 @@ TEST(MatchExpressionParserSchemaTest, MatchArrayIndexParsesSuccessfully) {
TEST(InternalSchemaAllElemMatchFromIndexMatchExpression, FailsToParseWithNegativeIndex) {
BSONObj matchPredicate =
fromjson("{$_internalSchemaAllElemMatchFromIndex: [-2, {a: { $lt: 0 }}]}");
- auto expr = MatchExpressionParser::parse(
- matchPredicate, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(matchPredicate, kSimpleCollator);
ASSERT_NOT_OK(expr.getStatus());
}
TEST(InternalSchemaAllElemMatchFromIndexMatchExpression, FailsToParseWithNonObjectExpression) {
BSONObj matchPredicate = fromjson("{$_internalSchemaAllElemMatchFromIndex: [-2, 4]}");
- auto expr = MatchExpressionParser::parse(
- matchPredicate, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(matchPredicate, kSimpleCollator);
ASSERT_NOT_OK(expr.getStatus());
}
TEST(InternalSchemaAllElemMatchFromIndexMatchExpression, FailsToParseWithInvalidExpression) {
BSONObj matchPredicate =
fromjson("{$_internalSchemaAllElemMatchFromIndex: [-2, {$fakeExpression: 4}]}");
- auto expr = MatchExpressionParser::parse(
- matchPredicate, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(matchPredicate, kSimpleCollator);
ASSERT_NOT_OK(expr.getStatus());
}
TEST(InternalSchemaAllElemMatchFromIndexMatchExpression, FailsToParseWithEmptyArray) {
BSONObj matchPredicate = fromjson("{$_internalSchemaAllElemMatchFromIndex: []}");
- auto expr = MatchExpressionParser::parse(
- matchPredicate, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(matchPredicate, kSimpleCollator);
ASSERT_NOT_OK(expr.getStatus());
}
TEST(InternalSchemaAllElemMatchFromIndexMatchExpression, ParsesCorreclyWithValidInput) {
auto query = fromjson("{a: {$_internalSchemaAllElemMatchFromIndex: [2, {a: { $lt: 4 }}]}}");
- auto expr = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto expr = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(expr.getStatus());
ASSERT_TRUE(expr.getValue()->matchesBSON(fromjson("{a: [5, 3, 3, 3, 3, 3]}")));
@@ -630,16 +551,14 @@ TEST(InternalSchemaAllElemMatchFromIndexMatchExpression, ParsesCorreclyWithValid
TEST(MatchExpressionParserSchemaTest, InternalTypeFailsToParseOnTypeMismatch) {
BSONObj query = BSON("x" << BSON("$_internalSchemaType" << BSONObj()));
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_NOT_OK(result.getStatus());
}
TEST(MatchExpressionParserSchemaTest, InternalTypeCanParseNumberAlias) {
BSONObj query = BSON("x" << BSON("$_internalSchemaType"
<< "number"));
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(result.getStatus());
ASSERT_EQ(result.getValue()->matchType(), MatchExpression::INTERNAL_SCHEMA_TYPE);
@@ -650,8 +569,7 @@ TEST(MatchExpressionParserSchemaTest, InternalTypeCanParseNumberAlias) {
TEST(MatchExpressionParserSchemaTest, InternalTypeCanParseLongAlias) {
BSONObj query = BSON("x" << BSON("$_internalSchemaType"
<< "long"));
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(result.getStatus());
ASSERT_EQ(result.getValue()->matchType(), MatchExpression::INTERNAL_SCHEMA_TYPE);
@@ -662,8 +580,7 @@ TEST(MatchExpressionParserSchemaTest, InternalTypeCanParseLongAlias) {
TEST(MatchExpressionParserSchemaTest, InternalTypeCanParseLongCode) {
BSONObj query = BSON("x" << BSON("$_internalSchemaType" << 18));
- auto result = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto result = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(result.getStatus());
ASSERT_EQ(result.getValue()->matchType(), MatchExpression::INTERNAL_SCHEMA_TYPE);
@@ -676,88 +593,68 @@ TEST(MatchExpressionParserSchemaTest, AllowedPropertiesFailsParsingIfAFieldIsMis
auto query = fromjson(
"{$_internalSchemaAllowedProperties:"
"{namePlaceholder: 'i', patternProperties: [], otherwise: {i: 1}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::FailedToParse);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::FailedToParse);
query = fromjson(
"{$_internalSchemaAllowedProperties:"
"{properties: [], patternProperties: [], otherwise: {i: 1}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::FailedToParse);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::FailedToParse);
query = fromjson(
"{$_internalSchemaAllowedProperties:"
"{properties: [], namePlaceholder: 'i', otherwise: {i: 1}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::FailedToParse);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::FailedToParse);
query = fromjson(
"{$_internalSchemaAllowedProperties:"
"{properties: [], namePlaceholder: 'i', patternProperties: []}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::FailedToParse);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::FailedToParse);
}
TEST(MatchExpressionParserSchemaTest, AllowedPropertiesFailsParsingIfNamePlaceholderNotAString) {
auto query = fromjson(
"{$_internalSchemaAllowedProperties:"
"{properties: [], namePlaceholder: 7, patternProperties: [], otherwise: {i: 1}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::TypeMismatch);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::TypeMismatch);
query = fromjson(
"{$_internalSchemaAllowedProperties:"
"{properties: [], namePlaceholder: /i/, patternProperties: [], otherwise: {i: 1}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::TypeMismatch);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::TypeMismatch);
}
TEST(MatchExpressionParserSchemaTest, AllowedPropertiesFailsParsingIfNamePlaceholderNotValid) {
auto query = fromjson(
"{$_internalSchemaAllowedProperties: {properties: [], namePlaceholder: 'Capital',"
"patternProperties: [], otherwise: {Capital: 1}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::BadValue);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::BadValue);
query = fromjson(
"{$_internalSchemaAllowedProperties:"
"{properties: [], namePlaceholder: '', patternProperties: [], otherwise: {'': 1}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::BadValue);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::BadValue);
}
TEST(MatchExpressionParserSchemaTest, AllowedPropertiesFailsParsingIfPropertiesNotAllStrings) {
auto query = fromjson(
"{$_internalSchemaAllowedProperties:"
"{properties: [7], namePlaceholder: 'i', patternProperties: [], otherwise: {i: 1}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::TypeMismatch);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::TypeMismatch);
query = fromjson(
"{$_internalSchemaAllowedProperties: {properties: ['x', {}], namePlaceholder: 'i',"
"patternProperties: [], otherwise: {i: 1}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::TypeMismatch);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::TypeMismatch);
}
TEST(MatchExpressionParserSchemaTest,
@@ -765,18 +662,14 @@ TEST(MatchExpressionParserSchemaTest,
auto query = fromjson(
"{$_internalSchemaAllowedProperties:"
"{properties: [], namePlaceholder: 'i', patternProperties: ['blah'], otherwise: {i: 1}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::TypeMismatch);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::TypeMismatch);
query = fromjson(
"{$_internalSchemaAllowedProperties: {properties: [], namePlaceholder: 'i',"
"otherwise: {i: 1}, patternProperties: [{regex: /a/, expression: {i: 0}}, 'blah']}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::TypeMismatch);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::TypeMismatch);
}
TEST(MatchExpressionParserSchemaTest,
@@ -784,18 +677,14 @@ TEST(MatchExpressionParserSchemaTest,
auto query = fromjson(
"{$_internalSchemaAllowedProperties: {properties: [], namePlaceholder: 'i',"
"patternProperties: [{foo: 1, bar: 1}], otherwise: {i: 1}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::FailedToParse);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::FailedToParse);
query = fromjson(
"{$_internalSchemaAllowedProperties: {properties: [], namePlaceholder: 'i',"
"patternProperties: [{regex: /a/, blah: 0}], otherwise: {i: 1}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::FailedToParse);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::FailedToParse);
}
TEST(MatchExpressionParserSchemaTest,
@@ -803,26 +692,20 @@ TEST(MatchExpressionParserSchemaTest,
auto query = fromjson(
"{$_internalSchemaAllowedProperties: {properties: [], namePlaceholder: 'i',"
"otherwise: {i: 0}, patternProperties: [{expression: {i: 0}}]}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::FailedToParse);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::FailedToParse);
query = fromjson(
"{$_internalSchemaAllowedProperties: {properties: [], namePlaceholder: 'i',"
"otherwise: {i: 0}, patternProperties: [{regex: 7, expression: {i: 0}}]}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::TypeMismatch);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::TypeMismatch);
query = fromjson(
"{$_internalSchemaAllowedProperties: {properties: [], namePlaceholder: 'i',"
"otherwise: {i: 0}, patternProperties: [{regex: 'notARegex', expression: {i: 0}}]}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::TypeMismatch);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::TypeMismatch);
}
TEST(MatchExpressionParserSchemaTest,
@@ -830,18 +713,14 @@ TEST(MatchExpressionParserSchemaTest,
auto query = fromjson(
"{$_internalSchemaAllowedProperties: {properties: [], namePlaceholder: 'i',"
"otherwise: {i: 0}, patternProperties: [{regex: /a/}]}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::FailedToParse);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::FailedToParse);
query = fromjson(
"{$_internalSchemaAllowedProperties: {properties: [], namePlaceholder: 'i',"
"otherwise: {i: 0}, patternProperties: [{regex: /a/, expression: 'blah'}]}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::TypeMismatch);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::TypeMismatch);
}
TEST(MatchExpressionParserSchemaTest,
@@ -849,64 +728,50 @@ TEST(MatchExpressionParserSchemaTest,
auto query = fromjson(
"{$_internalSchemaAllowedProperties: {properties: [], namePlaceholder: 'i',"
"otherwise: {i: 0}, patternProperties: [{regex: /a/i, expression: {i: 0}}]}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::BadValue);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::BadValue);
}
TEST(MatchExpressionParserSchemaTest, AllowedPropertiesFailsParsingIfMismatchingNamePlaceholders) {
auto query = fromjson(
"{$_internalSchemaAllowedProperties:"
"{properties: [], namePlaceholder: 'i', patternProperties: [], otherwise: {j: 1}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::FailedToParse);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::FailedToParse);
query = fromjson(
"{$_internalSchemaAllowedProperties: {properties: [], namePlaceholder: 'i',"
"patternProperties: [{regex: /a/, expression: {w: 7}}], otherwise: {i: 'foo'}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::FailedToParse);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::FailedToParse);
}
TEST(MatchExpressionParserSchemaTest, AllowedPropertiesFailsParsingIfOtherwiseIncorrectType) {
auto query = fromjson(
"{$_internalSchemaAllowedProperties:"
"{properties: [], namePlaceholder: 'i', patternProperties: [], otherwise: false}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::TypeMismatch);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::TypeMismatch);
query = fromjson(
"{$_internalSchemaAllowedProperties:"
"{properties: [], namePlaceholder: 'i', patternProperties: [], otherwise: [{i: 7}]}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::TypeMismatch);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::TypeMismatch);
}
TEST(MatchExpressionParserSchemaTest, AllowedPropertiesFailsParsingIfOtherwiseNotAValidExpression) {
auto query = fromjson(
"{$_internalSchemaAllowedProperties: {properties: [], namePlaceholder: 'i',"
"patternProperties: [], otherwise: {i: {$invalid: 1}}}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::BadValue);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::BadValue);
query = fromjson(
"{$_internalSchemaAllowedProperties:"
"{properties: [], namePlaceholder: 'i', patternProperties: [], otherwise: {}}}}}");
- ASSERT_EQ(
- MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator)
- .getStatus(),
- ErrorCodes::FailedToParse);
+ ASSERT_EQ(MatchExpressionParser::parse(query, kSimpleCollator).getStatus(),
+ ErrorCodes::FailedToParse);
}
TEST(MatchExpressionParserSchemaTest, AllowedPropertiesParsesSuccessfully) {
@@ -914,8 +779,7 @@ TEST(MatchExpressionParserSchemaTest, AllowedPropertiesParsesSuccessfully) {
"{$_internalSchemaAllowedProperties: {properties: ['phoneNumber', 'address'],"
"namePlaceholder: 'i', otherwise: {i: {$gt: 10}},"
"patternProperties: [{regex: /[nN]umber/, expression: {i: {$type: 'number'}}}]}}}");
- auto allowedProperties = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto allowedProperties = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(allowedProperties.getStatus());
ASSERT_TRUE(allowedProperties.getValue()->matchesBSON(
@@ -932,8 +796,7 @@ TEST(MatchExpressionParserSchemaTest, AllowedPropertiesAcceptsEmptyPropertiesAnd
auto query = fromjson(
"{$_internalSchemaAllowedProperties:"
"{properties: [], namePlaceholder: 'i', patternProperties: [], otherwise: {i: 1}}}}");
- auto allowedProperties = MatchExpressionParser::parse(
- query, ExtensionsCallbackDisallowExtensions(), kSimpleCollator);
+ auto allowedProperties = MatchExpressionParser::parse(query, kSimpleCollator);
ASSERT_OK(allowedProperties.getStatus());
ASSERT_TRUE(allowedProperties.getValue()->matchesBSON(BSONObj()));