Skip to content

Commit 2a4bf6a

Browse files
jakec-githubJake Chorley
andauthored
Errors on valid timestamps (#4973)
* Errors on valid timestamps * Improves error message on invalid timestamps --------- Co-authored-by: Jake Chorley <[email protected]>
1 parent 1cf390f commit 2a4bf6a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

runtime/query.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,11 @@ func parseMessage(msgDescriptor protoreflect.MessageDescriptor, value string) (p
291291
if err != nil {
292292
return protoreflect.Value{}, err
293293
}
294-
msg = timestamppb.New(t)
294+
timestamp := timestamppb.New(t)
295+
if ok := timestamp.IsValid(); !ok {
296+
return protoreflect.Value{}, fmt.Errorf("%s before 0001-01-01", value)
297+
}
298+
msg = timestamp
295299
case "google.protobuf.Duration":
296300
d, err := time.ParseDuration(value)
297301
if err != nil {

runtime/query_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,14 @@ func TestPopulateParameters(t *testing.T) {
495495
want: &examplepb.Proto3Message{},
496496
wanterr: errors.New("invalid path: \"repeated_message\" is not a message"),
497497
},
498+
{
499+
values: url.Values{
500+
"timestampValue": {"0000-01-01T00:00:00.00Z"},
501+
},
502+
filter: utilities.NewDoubleArray(nil),
503+
want: &examplepb.Proto3Message{},
504+
wanterr: errors.New(`parsing field "timestamp_value": 0000-01-01T00:00:00.00Z before 0001-01-01`),
505+
},
498506
} {
499507
t.Run(strconv.Itoa(i), func(t *testing.T) {
500508
msg := spec.want.ProtoReflect().New().Interface()

0 commit comments

Comments
 (0)