Skip to content

Commit

Permalink
make date expiry parsing use end of day (#3298)
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic committed Sep 30, 2022
1 parent bcd3306 commit bcad854
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/expiry-parsing-date-only-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Make date only expiry dates valid for the whole day

When an expiry date like `2022-09-30` is parsed, we now make it valid for the whole day, effectively becoming `2022-09-30 23:59:59`

https://github.com/cs3org/reva/pull/3298
8 changes: 6 additions & 2 deletions internal/http/services/owncloud/ocs/conversions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,18 @@ func timestampToExpiration(t *types.Timestamp) string {
return time.Unix(int64(t.Seconds), int64(t.Nanos)).UTC().Format("2006-01-02 15:05:05")
}

// ParseTimestamp tries to parses the ocs expiry into a CS3 Timestamp
// ParseTimestamp tries to parse the ocs expiry into a CS3 Timestamp
func ParseTimestamp(timestampString string) (*types.Timestamp, error) {
parsedTime, err := time.Parse("2006-01-02T15:04:05Z0700", timestampString)
if err != nil {
parsedTime, err = time.Parse("2006-01-02", timestampString)
if err == nil {
// the link needs to be valid for the whole day
parsedTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
}
}
if err != nil {
return nil, fmt.Errorf("datetime format invalid: %v", timestampString)
return nil, fmt.Errorf("datetime format invalid: %v, %s", timestampString, err.Error())
}
final := parsedTime.UnixNano()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ func (h *Handler) createPublicLinkShare(w http.ResponseWriter, r *http.Request,
expireTime, err := conversions.ParseTimestamp(expireTimeString[0])
if err != nil {
return nil, &ocsError{
Code: response.MetaServerError.StatusCode,
Message: "invalid datetime format",
Code: response.MetaBadRequest.StatusCode,
Message: err.Error(),
Error: err,
}
}
Expand Down

0 comments on commit bcad854

Please sign in to comment.