Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make date expiry parsing use end of day #3298

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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