Skip to content

Commit

Permalink
Fix nil pointer exception in codec timestamp handling (#187)
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Nichols <nicholss@google.com>
  • Loading branch information
n3wscott authored and markpeek committed Sep 13, 2019
1 parent 5bacd6c commit 4cc108a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions pkg/cloudevents/transport/amqp/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,17 @@ func (c Codec) fromHeaders(h map[string]interface{}, event *cloudevents.Event) e
}
delete(h, prefix+"source")

if t, ok := h[prefix+"time"].(string); ok { // TODO: time can be empty
timestamp := types.ParseTimestamp(t)
if err := ec.SetTime(timestamp.Time); err != nil {
return err
if t, ok := h[prefix+"time"].(string); ok {
if timestamp := types.ParseTimestamp(t); timestamp != nil {
if err := ec.SetTime(timestamp.Time); err != nil {
return err
}
}
}
delete(h, prefix+"time")

if t, ok := h[prefix+"schemaurl"].(string); ok {
timestamp := types.ParseTimestamp(t)
if err := ec.SetTime(timestamp.Time); err != nil {
if s, ok := h[prefix+"schemaurl"].(string); ok {
if err := ec.SetSchemaURL(s); err != nil {
return err
}
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/cloudevents/transport/pubsub/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,16 @@ func (c Codec) fromAttributes(a map[string]string, event *cloudevents.Event) err
delete(a, prefix+"source")

if t := a[prefix+"time"]; t != "" {
timestamp := types.ParseTimestamp(t)
if err := ec.SetTime(timestamp.Time); err != nil {
return err
if timestamp := types.ParseTimestamp(t); timestamp != nil {
if err := ec.SetTime(timestamp.Time); err != nil {
return err
}
}
}
delete(a, prefix+"time")

if t := a[prefix+"schemaurl"]; t != "" {
timestamp := types.ParseTimestamp(t)
if err := ec.SetTime(timestamp.Time); err != nil {
if s := a[prefix+"schemaurl"]; s != "" {
if err := ec.SetSchemaURL(s); err != nil {
return err
}
}
Expand Down

0 comments on commit 4cc108a

Please sign in to comment.