Skip to content

Commit

Permalink
Errors on valid timestamps (#4973)
Browse files Browse the repository at this point in the history
* Errors on valid timestamps

* Improves error message on invalid timestamps

---------

Co-authored-by: Jake Chorley <jakechorley@192.168.1.197>
  • Loading branch information
jakec-github and Jake Chorley authored Nov 22, 2024
1 parent 1cf390f commit 2a4bf6a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion runtime/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions runtime/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2a4bf6a

Please sign in to comment.