Skip to content

Commit d5449f5

Browse files
committed
Fixed issue with Inf in a vector when using Proto3JSON.
1 parent 2a365b8 commit d5449f5

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

packages/firestore/src/lite-api/user_data_reader.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import {
5151
MapValue as ProtoMapValue,
5252
Value as ProtoValue
5353
} from '../protos/firestore_proto_api';
54-
import { toNumber } from '../remote/number_serializer';
54+
import { toDouble, toNumber } from '../remote/number_serializer';
5555
import {
5656
JsonProtoSerializer,
5757
toBytes,
@@ -908,7 +908,7 @@ function parseScalarValue(
908908
)
909909
};
910910
} else if (value instanceof VectorValue) {
911-
return parseVectorValue(value);
911+
return parseVectorValue(value, context);
912912
} else {
913913
throw context.createError(
914914
`Unsupported field value: ${valueDescription(value)}`
@@ -919,7 +919,10 @@ function parseScalarValue(
919919
/**
920920
* Creates a new VectorValue proto value (using the internal format).
921921
*/
922-
export function parseVectorValue(value: VectorValue): ProtoValue {
922+
export function parseVectorValue(
923+
value: VectorValue,
924+
context: ParseContextImpl
925+
): ProtoValue {
923926
const mapValue: ProtoMapValue = {
924927
fields: {
925928
[TYPE_KEY]: {
@@ -928,9 +931,13 @@ export function parseVectorValue(value: VectorValue): ProtoValue {
928931
[VECTOR_MAP_VECTORS_KEY]: {
929932
arrayValue: {
930933
values: value.toArray().map(value => {
931-
return {
932-
doubleValue: value
933-
};
934+
if (typeof value !== 'number') {
935+
throw context.createError(
936+
'VectorValues must only contain numeric values.'
937+
);
938+
}
939+
940+
return toDouble(context.serializer, value);
934941
})
935942
}
936943
}

0 commit comments

Comments
 (0)