mirror of
https://github.com/firebase/firebase-ios-sdk
synced 2026-11-09 22:36:01 +05:45
Disallow empty document fields (#4229)
Port of firebase/firebase-android-sdk#643. Also make error messages align with Android's.
This commit is contained in:
2 files changed
+22
-10
No files matched your search
@@ -263,23 +263,30 @@ namespace testutil = firebase::firestore::testutil;
|
||||
|
||||
- (void)testWritesWithReservedFieldsFail {
|
||||
[self expectWrite:@{@"__baz__" : @1}
|
||||
toFailWithReason:@"Document fields cannot begin and end with __ (found in field __baz__)"];
|
||||
toFailWithReason:@"Invalid data. Document fields cannot begin and end with \"__\" (found in "
|
||||
@"field __baz__)"];
|
||||
[self expectWrite:@{@"foo" : @{@"__baz__" : @1}}
|
||||
toFailWithReason:
|
||||
@"Document fields cannot begin and end with __ (found in field foo.__baz__)"];
|
||||
toFailWithReason:@"Invalid data. Document fields cannot begin and end with \"__\" (found in "
|
||||
@"field foo.__baz__)"];
|
||||
[self expectWrite:@{@"__baz__" : @{@"foo" : @1}}
|
||||
toFailWithReason:@"Document fields cannot begin and end with __ (found in field __baz__)"];
|
||||
toFailWithReason:@"Invalid data. Document fields cannot begin and end with \"__\" (found in "
|
||||
@"field __baz__)"];
|
||||
|
||||
[self expectUpdate:@{@"foo.__baz__" : @1}
|
||||
toFailWithReason:
|
||||
@"Document fields cannot begin and end with __ (found in field foo.__baz__)"];
|
||||
toFailWithReason:@"Invalid data. Document fields cannot begin and end with \"__\" (found in "
|
||||
@"field foo.__baz__)"];
|
||||
[self expectUpdate:@{@"__baz__.foo" : @1}
|
||||
toFailWithReason:
|
||||
@"Document fields cannot begin and end with __ (found in field __baz__.foo)"];
|
||||
toFailWithReason:@"Invalid data. Document fields cannot begin and end with \"__\" (found in "
|
||||
@"field __baz__.foo)"];
|
||||
[self expectUpdate:@{@1 : @1}
|
||||
toFailWithReason:@"Dictionary keys in updateData: must be NSStrings or FIRFieldPaths."];
|
||||
}
|
||||
|
||||
- (void)testWritesMustNotContainEmptyFieldNames {
|
||||
[self expectSet:@{@"" : @"foo"}
|
||||
toFailWithReason:@"Invalid data. Document fields must not be empty (found in field ``)"];
|
||||
}
|
||||
|
||||
- (void)testSetsWithFieldValueDeleteFail {
|
||||
[self expectSet:@{@"foo" : [FIRFieldValue fieldValueForDelete]}
|
||||
toFailWithReason:@"FieldValue.delete() can only be used with updateData() and setData() with "
|
||||
|
||||
@@ -181,10 +181,15 @@ void ParseContext::ValidatePath() const {
|
||||
|
||||
void ParseContext::ValidatePathSegment(absl::string_view segment) const {
|
||||
absl::string_view designator{RESERVED_FIELD_DESIGNATOR};
|
||||
if (segment.empty()) {
|
||||
ThrowInvalidArgument("Invalid data. Document fields must not be empty%s",
|
||||
FieldDescription());
|
||||
}
|
||||
if (write() && absl::StartsWith(segment, designator) &&
|
||||
absl::EndsWith(segment, designator)) {
|
||||
ThrowInvalidArgument("Document fields cannot begin and end with %s%s",
|
||||
RESERVED_FIELD_DESIGNATOR, FieldDescription());
|
||||
ThrowInvalidArgument(
|
||||
"Invalid data. Document fields cannot begin and end with \"%s\"%s",
|
||||
RESERVED_FIELD_DESIGNATOR, FieldDescription());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user