diff options
author | Nick Zolnierz <nicholas.zolnierz@mongodb.com> | 2018-09-21 14:35:16 -0400 |
---|---|---|
committer | Nick Zolnierz <nicholas.zolnierz@mongodb.com> | 2018-10-04 09:53:18 -0400 |
commit | 41820e4b371e389e8cbe965dc9aff14f657a9040 (patch) | |
tree | 511ef7e3e15a067f0f0a2dd93495b0f3b18e6050 /src/mongo/db/field_ref.cpp | |
parent | 1e026f75dc41cca4c7293e42b5b49cb9e46d0ea3 (diff) | |
download | mongo-41820e4b371e389e8cbe965dc9aff14f657a9040.tar.gz |
SERVER-37058: Update with numeric field names inside an array can cause validation to fail
Diffstat (limited to 'src/mongo/db/field_ref.cpp')
-rw-r--r-- | src/mongo/db/field_ref.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/mongo/db/field_ref.cpp b/src/mongo/db/field_ref.cpp index 1bce17b20e7..d6fb5e85f9d 100644 --- a/src/mongo/db/field_ref.cpp +++ b/src/mongo/db/field_ref.cpp @@ -251,18 +251,23 @@ size_t FieldRef::commonPrefixSize(const FieldRef& other) const { return prefixSize; } -bool FieldRef::isNumericPathComponent(StringData component) { +bool FieldRef::isNumericPathComponentStrict(StringData component) { return !component.empty() && !(component.size() > 1 && component[0] == '0') && + FieldRef::isNumericPathComponentLenient(component); +} + +bool FieldRef::isNumericPathComponentLenient(StringData component) { + return !component.empty() && std::all_of(component.begin(), component.end(), [](auto c) { return std::isdigit(c); }); } -bool FieldRef::isNumericPathComponent(size_t i) const { - return FieldRef::isNumericPathComponent(getPart(i)); +bool FieldRef::isNumericPathComponentStrict(size_t i) const { + return FieldRef::isNumericPathComponentStrict(getPart(i)); } bool FieldRef::hasNumericPathComponents() const { for (size_t i = 0; i < numParts(); ++i) { - if (isNumericPathComponent(i)) + if (isNumericPathComponentStrict(i)) return true; } return false; @@ -271,7 +276,7 @@ bool FieldRef::hasNumericPathComponents() const { std::set<size_t> FieldRef::getNumericPathComponents(size_t startPart) const { std::set<size_t> numericPathComponents; for (auto i = startPart; i < numParts(); ++i) { - if (isNumericPathComponent(i)) + if (isNumericPathComponentStrict(i)) numericPathComponents.insert(i); } return numericPathComponents; |