Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add quotes to field name validation to avoid ambiguity #860

Merged
merged 2 commits into from Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/src/serializer.ts
Expand Up @@ -308,7 +308,7 @@ export function validateUserInput(
level = level || 0;
inArray = inArray || false;

const fieldPathMessage = path ? ` (found in field ${path})` : '';
const fieldPathMessage = path ? ` (found in field "${path}")` : '';

if (Array.isArray(value)) {
for (let i = 0; i < value.length; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion dev/src/validate.ts
Expand Up @@ -67,7 +67,7 @@ export function customObjectMessage(
value: unknown,
path?: FieldPath
): string {
const fieldPathMessage = path ? ` (found in field ${path})` : '';
const fieldPathMessage = path ? ` (found in field "${path}")` : '';

if (isObject(value)) {
// We use the base class name as the type name as the sentinel classes
Expand Down
12 changes: 6 additions & 6 deletions dev/test/document.ts
Expand Up @@ -140,22 +140,22 @@ describe('serialize document', () => {
expect(() => {
firestore.doc('collectionId/documentId').set({foo: undefined});
}).to.throw(
'Value for argument "data" is not a valid Firestore document. Cannot use "undefined" as a Firestore value (found in field foo).'
'Value for argument "data" is not a valid Firestore document. Cannot use "undefined" as a Firestore value (found in field "foo").'
);

expect(() => {
firestore.doc('collectionId/documentId').set({
foo: FieldPath.documentId(),
});
}).to.throw(
'Value for argument "data" is not a valid Firestore document. Cannot use object of type "FieldPath" as a Firestore value (found in field foo).'
'Value for argument "data" is not a valid Firestore document. Cannot use object of type "FieldPath" as a Firestore value (found in field "foo").'
);

expect(() => {
class Foo {}
firestore.doc('collectionId/documentId').set({foo: new Foo()});
}).to.throw(
'Value for argument "data" is not a valid Firestore document. Couldn\'t serialize object of type "Foo" (found in field foo). Firestore doesn\'t support JavaScript objects with custom prototypes (i.e. objects that were created via the "new" operator).'
'Value for argument "data" is not a valid Firestore document. Couldn\'t serialize object of type "Foo" (found in field "foo"). Firestore doesn\'t support JavaScript objects with custom prototypes (i.e. objects that were created via the "new" operator).'
);

expect(() => {
Expand Down Expand Up @@ -1238,7 +1238,7 @@ describe('set document', () => {
expect(() => {
firestore.doc('collectionId/documentId').set({foo: FieldValue.delete()});
}).to.throw(
'Value for argument "data" is not a valid Firestore document. FieldValue.delete() must appear at the top-level and can only be used in update() or set() with {merge:true} (found in field foo).'
'Value for argument "data" is not a valid Firestore document. FieldValue.delete() must appear at the top-level and can only be used in update() or set() with {merge:true} (found in field "foo").'
);
});

Expand Down Expand Up @@ -1587,15 +1587,15 @@ describe('update document', () => {
a: {b: FieldValue.delete()},
});
}).to.throw(
'Update() requires either a single JavaScript object or an alternating list of field/value pairs that can be followed by an optional precondition. Value for argument "dataOrField" is not a valid Firestore value. FieldValue.delete() must appear at the top-level and can only be used in update() or set() with {merge:true} (found in field a.b).'
'Update() requires either a single JavaScript object or an alternating list of field/value pairs that can be followed by an optional precondition. Value for argument "dataOrField" is not a valid Firestore value. FieldValue.delete() must appear at the top-level and can only be used in update() or set() with {merge:true} (found in field "a.b").'
);

expect(() => {
firestore.doc('collectionId/documentId').update('a', {
b: FieldValue.delete(),
});
}).to.throw(
'Update() requires either a single JavaScript object or an alternating list of field/value pairs that can be followed by an optional precondition. Element at index 1 is not a valid Firestore value. FieldValue.delete() must appear at the top-level and can only be used in update() or set() with {merge:true} (found in field a.b).'
'Update() requires either a single JavaScript object or an alternating list of field/value pairs that can be followed by an optional precondition. Element at index 1 is not a valid Firestore value. FieldValue.delete() must appear at the top-level and can only be used in update() or set() with {merge:true} (found in field "a.b").'
);

expect(() => {
Expand Down