From 647aa2c0f612cde385a2efb7150d05ea5f442533 Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Wed, 2 Nov 2016 19:31:32 -0700 Subject: [PATCH] Fix max expiry when provided expiry is 0 Previously, we did not properly handle the case where the provided expiry was zero and the max expiry was configured to be nonzero; add an additional check to cover this case. Fixes #111. --- server_test.go | 4 +++- upload.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/server_test.go b/server_test.go index af7abe0..a590465 100644 --- a/server_test.go +++ b/server_test.go @@ -450,7 +450,9 @@ func TestPostJSONUploadMaxExpiry(t *testing.T) { mux := setup() Config.maxExpiry = 300 - testExpiries := []string{"86400", "-150"} + // include 0 to test edge case + // https://github.com/andreimarcu/linx-server/issues/111 + testExpiries := []string{"86400", "-150", "0"} for _, expiry := range testExpiries { w := httptest.NewRecorder() diff --git a/upload.go b/upload.go index e67a20a..1233d1a 100644 --- a/upload.go +++ b/upload.go @@ -349,7 +349,7 @@ func parseExpiry(expStr string) time.Duration { if err != nil { return time.Duration(Config.maxExpiry) * time.Second } else { - if Config.maxExpiry > 0 && expiry > Config.maxExpiry { + if Config.maxExpiry > 0 && (expiry > Config.maxExpiry || expiry == 0) { expiry = Config.maxExpiry } return time.Duration(expiry) * time.Second