From f8b622c55c0ef3a7de9a9ee640eaaeb8e2da50aa Mon Sep 17 00:00:00 2001 From: Jake Chorley Date: Wed, 20 Nov 2024 17:51:57 +0000 Subject: [PATCH 1/2] Errors on valid timestamps --- 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..cefdefc5999 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 is not a valid timestamp", 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..90e41d084d3 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 is not a valid timestamp`), + }, } { t.Run(strconv.Itoa(i), func(t *testing.T) { msg := spec.want.ProtoReflect().New().Interface() From b5f8d54c4a5af779601b087e3b8dc5a11c3ead29 Mon Sep 17 00:00:00 2001 From: Jake Chorley Date: Thu, 21 Nov 2024 22:53:38 +0000 Subject: [PATCH 2/2] Improves error message on invalid timestamps --- runtime/query.go | 2 +- runtime/query_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/query.go b/runtime/query.go index cefdefc5999..93fb09922fb 100644 --- a/runtime/query.go +++ b/runtime/query.go @@ -293,7 +293,7 @@ func parseMessage(msgDescriptor protoreflect.MessageDescriptor, value string) (p } timestamp := timestamppb.New(t) if ok := timestamp.IsValid(); !ok { - return protoreflect.Value{}, fmt.Errorf("%s is not a valid timestamp", value) + return protoreflect.Value{}, fmt.Errorf("%s before 0001-01-01", value) } msg = timestamp case "google.protobuf.Duration": diff --git a/runtime/query_test.go b/runtime/query_test.go index 90e41d084d3..5dfbbf5a34c 100644 --- a/runtime/query_test.go +++ b/runtime/query_test.go @@ -501,7 +501,7 @@ func TestPopulateParameters(t *testing.T) { }, filter: utilities.NewDoubleArray(nil), want: &examplepb.Proto3Message{}, - wanterr: errors.New(`parsing field "timestamp_value": 0000-01-01T00:00:00.00Z is not a valid timestamp`), + 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) {