diff --git a/httpd/httpd_test.go b/httpd/httpd_test.go index b714ed45..a9f3596e 100644 --- a/httpd/httpd_test.go +++ b/httpd/httpd_test.go @@ -6189,26 +6189,32 @@ func TestAddWebFoldersMock(t *testing.T) { form.Set("mapped_path", mappedPath) form.Set("name", folderName) form.Set("description", folderDesc) - req, err := http.NewRequest(http.MethodPost, webFolderPath, strings.NewReader(form.Encode())) + b, contentType, err := getMultipartFormData(form, "", "") assert.NoError(t, err) + req, err := http.NewRequest(http.MethodPost, webFolderPath, &b) + assert.NoError(t, err) + req.Header.Set("Content-Type", contentType) setJWTCookieForReq(req, webToken) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") rr := executeRequest(req) checkResponseCode(t, http.StatusForbidden, rr) assert.Contains(t, rr.Body.String(), "unable to verify form token") form.Set(csrfFormToken, csrfToken) - req, err = http.NewRequest(http.MethodPost, webFolderPath, strings.NewReader(form.Encode())) + b, contentType, err = getMultipartFormData(form, "", "") assert.NoError(t, err) + req, err = http.NewRequest(http.MethodPost, webFolderPath, &b) + assert.NoError(t, err) + req.Header.Set("Content-Type", contentType) setJWTCookieForReq(req, webToken) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") rr = executeRequest(req) checkResponseCode(t, http.StatusSeeOther, rr) // adding the same folder will fail since the name must be unique - req, err = http.NewRequest(http.MethodPost, webFolderPath, strings.NewReader(form.Encode())) + b, contentType, err = getMultipartFormData(form, "", "") + assert.NoError(t, err) + req, err = http.NewRequest(http.MethodPost, webFolderPath, &b) assert.NoError(t, err) setJWTCookieForReq(req, webToken) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + req.Header.Set("Content-Type", contentType) rr = executeRequest(req) checkResponseCode(t, http.StatusOK, rr) // invalid form @@ -6277,18 +6283,22 @@ func TestS3WebFolderMock(t *testing.T) { form.Set("s3_upload_part_size", strconv.Itoa(S3UploadPartSize)) form.Set("s3_upload_concurrency", "a") form.Set(csrfFormToken, csrfToken) - req, err := http.NewRequest(http.MethodPost, webFolderPath, strings.NewReader(form.Encode())) + b, contentType, err := getMultipartFormData(form, "", "") + assert.NoError(t, err) + req, err := http.NewRequest(http.MethodPost, webFolderPath, &b) assert.NoError(t, err) setJWTCookieForReq(req, webToken) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + req.Header.Set("Content-Type", contentType) rr := executeRequest(req) checkResponseCode(t, http.StatusOK, rr) form.Set("s3_upload_concurrency", strconv.Itoa(S3UploadConcurrency)) - req, err = http.NewRequest(http.MethodPost, webFolderPath, strings.NewReader(form.Encode())) + b, contentType, err = getMultipartFormData(form, "", "") + assert.NoError(t, err) + req, err = http.NewRequest(http.MethodPost, webFolderPath, &b) assert.NoError(t, err) setJWTCookieForReq(req, webToken) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + req.Header.Set("Content-Type", contentType) rr = executeRequest(req) checkResponseCode(t, http.StatusSeeOther, rr) @@ -6315,18 +6325,22 @@ func TestS3WebFolderMock(t *testing.T) { // update S3UploadConcurrency = 10 form.Set("s3_upload_concurrency", "b") - req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), strings.NewReader(form.Encode())) + b, contentType, err = getMultipartFormData(form, "", "") + assert.NoError(t, err) + req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), &b) assert.NoError(t, err) setJWTCookieForReq(req, webToken) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + req.Header.Set("Content-Type", contentType) rr = executeRequest(req) checkResponseCode(t, http.StatusOK, rr) form.Set("s3_upload_concurrency", strconv.Itoa(S3UploadConcurrency)) - req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), strings.NewReader(form.Encode())) + b, contentType, err = getMultipartFormData(form, "", "") + assert.NoError(t, err) + req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), &b) assert.NoError(t, err) setJWTCookieForReq(req, webToken) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + req.Header.Set("Content-Type", contentType) rr = executeRequest(req) checkResponseCode(t, http.StatusSeeOther, rr) @@ -6380,19 +6394,23 @@ func TestUpdateWebFolderMock(t *testing.T) { form.Set("name", folderName) form.Set("description", folderDesc) form.Set(csrfFormToken, "") - req, err := http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), strings.NewReader(form.Encode())) + b, contentType, err := getMultipartFormData(form, "", "") + assert.NoError(t, err) + req, err := http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), &b) assert.NoError(t, err) setJWTCookieForReq(req, webToken) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + req.Header.Set("Content-Type", contentType) rr := executeRequest(req) checkResponseCode(t, http.StatusForbidden, rr) assert.Contains(t, rr.Body.String(), "unable to verify form token") form.Set(csrfFormToken, csrfToken) - req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), strings.NewReader(form.Encode())) + b, contentType, err = getMultipartFormData(form, "", "") + assert.NoError(t, err) + req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), &b) assert.NoError(t, err) setJWTCookieForReq(req, webToken) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + req.Header.Set("Content-Type", contentType) rr = executeRequest(req) checkResponseCode(t, http.StatusSeeOther, rr) @@ -6407,26 +6425,32 @@ func TestUpdateWebFolderMock(t *testing.T) { assert.Equal(t, folderDesc, folder.Description) // parse form error - req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName)+"??a=a%B3%A2%G3", strings.NewReader(form.Encode())) + b, contentType, err = getMultipartFormData(form, "", "") + assert.NoError(t, err) + req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName)+"??a=a%B3%A2%G3", &b) assert.NoError(t, err) setJWTCookieForReq(req, webToken) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + req.Header.Set("Content-Type", contentType) rr = executeRequest(req) checkResponseCode(t, http.StatusOK, rr) assert.Contains(t, rr.Body.String(), "invalid URL escape") - req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName+"1"), strings.NewReader(form.Encode())) + b, contentType, err = getMultipartFormData(form, "", "") + assert.NoError(t, err) + req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName+"1"), &b) assert.NoError(t, err) setJWTCookieForReq(req, webToken) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + req.Header.Set("Content-Type", contentType) rr = executeRequest(req) checkResponseCode(t, http.StatusNotFound, rr) form.Set("mapped_path", "arelative/path") - req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), strings.NewReader(form.Encode())) + b, contentType, err = getMultipartFormData(form, "", "") + assert.NoError(t, err) + req, err = http.NewRequest(http.MethodPost, path.Join(webFolderPath, folderName), &b) assert.NoError(t, err) setJWTCookieForReq(req, webToken) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + req.Header.Set("Content-Type", contentType) rr = executeRequest(req) checkResponseCode(t, http.StatusOK, rr) diff --git a/httpd/web.go b/httpd/web.go index c28b502b..9fe1b9d8 100644 --- a/httpd/web.go +++ b/httpd/web.go @@ -1478,7 +1478,7 @@ func handleWebAddFolderGet(w http.ResponseWriter, r *http.Request) { func handleWebAddFolderPost(w http.ResponseWriter, r *http.Request) { r.Body = http.MaxBytesReader(w, r.Body, maxRequestSize) folder := vfs.BaseVirtualFolder{} - err := r.ParseForm() + err := r.ParseMultipartForm(maxRequestSize) if err != nil { renderFolderPage(w, r, folder, folderPageModeAdd, err.Error()) return @@ -1529,7 +1529,7 @@ func handleWebUpdateFolderPost(w http.ResponseWriter, r *http.Request) { return } - err = r.ParseForm() + err = r.ParseMultipartForm(maxRequestSize) if err != nil { renderFolderPage(w, r, folder, folderPageModeUpdate, err.Error()) return diff --git a/templates/folder.html b/templates/folder.html index 3892ee01..4dc6122b 100644 --- a/templates/folder.html +++ b/templates/folder.html @@ -27,7 +27,7 @@ {{end}} -
+ {{if eq .Mode 3}}