From 695d94255348302be2d804e2187eb61e15cbb412 Mon Sep 17 00:00:00 2001 From: Nick Zolnierz Date: Thu, 1 Feb 2018 11:12:12 -0500 Subject: SERVER-30523: dateFromParts should not reject out-of-range numbers for date/time properties --- src/mongo/db/pipeline/expression.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/mongo/db/pipeline/expression.h') diff --git a/src/mongo/db/pipeline/expression.h b/src/mongo/db/pipeline/expression.h index 7d055e1a963..2e0d899ed12 100644 --- a/src/mongo/db/pipeline/expression.h +++ b/src/mongo/db/pipeline/expression.h @@ -910,16 +910,22 @@ private: boost::intrusive_ptr timeZone); /** - * Evaluates the value in field as number, and makes sure it fits in the minValue..maxValue - * range. If the field is missing or empty, the function returns the defaultValue. + * This function checks whether a field is a number. + * + * If 'field' is null, the default value is returned trough the 'returnValue' out + * parameter and the function returns true. + * + * If 'field' is not null: + * - if the value is "nullish", the function returns false. + * - if the value can not be coerced to an integral value, a UserException is thrown. + * - otherwise, the coerced integral value is returned through the 'returnValue' + * out parameter, and the function returns true. */ - bool evaluateNumberWithinRange(const Document& root, - const Expression* field, + bool evaluateNumberWithDefault(const Document& root, + boost::intrusive_ptr field, StringData fieldName, - int defaultValue, - int minValue, - int maxValue, - int* returnValue) const; + long long defaultValue, + long long* returnValue) const; boost::intrusive_ptr _year; boost::intrusive_ptr _month; -- cgit v1.2.1