From 2a4bf6a6169c26d44826c47f72f2b55b27da7b71 Mon Sep 17 00:00:00 2001 From: Jake Chorley Date: Fri, 22 Nov 2024 00:09:14 +0000 Subject: [PATCH] Errors on valid timestamps (#4973) * Errors on valid timestamps * Improves error message on invalid timestamps --------- Co-authored-by: Jake Chorley --- runtime/query.go | 6 +++++- runtime/query_test.go | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/runtime/query.go b/runtime/query.go index fe634174b85..93fb09922fb 100644 --- a/runtime/query.go +++ b/runtime/query.go @@ -291,7 +291,11 @@ func parseMessage(msgDescriptor protoreflect.MessageDescriptor, value string) (p if err != nil { return protoreflect.Value{}, err } - msg = timestamppb.New(t) + timestamp := timestamppb.New(t) + if ok := timestamp.IsValid(); !ok { + return protoreflect.Value{}, fmt.Errorf("%s before 0001-01-01", value) + } + msg = timestamp case "google.protobuf.Duration": d, err := time.ParseDuration(value) if err != nil { diff --git a/runtime/query_test.go b/runtime/query_test.go index 16c11e946f3..5dfbbf5a34c 100644 --- a/runtime/query_test.go +++ b/runtime/query_test.go @@ -495,6 +495,14 @@ func TestPopulateParameters(t *testing.T) { want: &examplepb.Proto3Message{}, wanterr: errors.New("invalid path: \"repeated_message\" is not a message"), }, + { + values: url.Values{ + "timestampValue": {"0000-01-01T00:00:00.00Z"}, + }, + filter: utilities.NewDoubleArray(nil), + want: &examplepb.Proto3Message{}, + wanterr: errors.New(`parsing field "timestamp_value": 0000-01-01T00:00:00.00Z before 0001-01-01`), + }, } { t.Run(strconv.Itoa(i), func(t *testing.T) { msg := spec.want.ProtoReflect().New().Interface()