Compare commits

..

No commits in common. "5eb09842e83a73f4075340331741c3e36ffca67a" and "b4751de6323ad7a9a1e7ed8640d9589f4e648859" have entirely different histories.

2 changed files with 21 additions and 20 deletions

View file

@ -51,12 +51,12 @@ import (
_ "code.gitea.io/gitea/modules/session" // to registers all internal adapters _ "code.gitea.io/gitea/modules/session" // to registers all internal adapters
"code.forgejo.org/go-chi/binding"
"code.forgejo.org/go-chi/captcha" "code.forgejo.org/go-chi/captcha"
chi_middleware "github.com/go-chi/chi/v5/middleware" chi_middleware "github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/cors" "github.com/go-chi/cors"
"github.com/klauspost/compress/gzhttp" "github.com/klauspost/compress/gzhttp"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"code.forgejo.org/go-chi/binding"
) )
var GzipMinSize = gzhttp.DefaultMinSize var GzipMinSize = gzhttp.DefaultMinSize
@ -1674,18 +1674,19 @@ func registerRoutes(m *web.Route) {
} }
func BindUpload(f forms.UploadRepoFileForm) http.HandlerFunc { func BindUpload(f forms.UploadRepoFileForm) http.HandlerFunc {
return func(resp http.ResponseWriter, req *http.Request) { return func(resp http.ResponseWriter, req *http.Request) {
theObj := new(forms.UploadRepoFileForm) // create a new form obj for every request but not use obj directly
data := middleware.GetContextData(req.Context()) theObj := new(forms.UploadRepoFileForm) // create a new form obj for every request but not use obj directly
binding.Bind(req, theObj) data := middleware.GetContextData(req.Context())
files := theObj.Files binding.Bind(req, theObj)
var fullpaths []string files := theObj.Files
for _, fileID := range files { var fullpaths []string
fullPath := req.Form.Get("files_fullpath[" + fileID + "]") for _, fileID := range files {
fullpaths = append(fullpaths, fullPath) fullPath := req.Form.Get("files_fullpath[" + fileID + "]")
} fullpaths = append(fullpaths, fullPath)
theObj.FullPaths = fullpaths }
data.GetData()["__form"] = theObj theObj.FullPaths = fullpaths
middleware.AssignForm(theObj, data) data.GetData()["__form"] = theObj
} middleware.AssignForm(theObj, data)
}
} }

View file

@ -6,11 +6,11 @@ package files
import ( import (
"context" "context"
"fmt" "fmt"
"html"
"os" "os"
"path" "path"
"regexp"
"strings" "strings"
"regexp"
"html"
git_model "code.gitea.io/gitea/models/git" git_model "code.gitea.io/gitea/models/git"
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
@ -168,12 +168,12 @@ var fileNameSanitizeRegexp = regexp.MustCompile(`(?i)\.\.|[<>:\"\\|?*\x{0000}-\x
// Sanitize user input to valid OS filenames // Sanitize user input to valid OS filenames
// //
// Based on https://github.com/sindresorhus/filename-reserved-regex // Based on https://github.com/sindresorhus/filename-reserved-regex
// Adds ".." to prevent directory traversal // Adds ".." to prevent directory traversal
func fileNameSanitize(s string) string { func fileNameSanitize(s string) string {
// Added this because I am not sure what Windows will deliver us \ or / but we need /. // Added this because I am not sure what Windows will deliver us \ or / but we need /.
s = strings.ReplaceAll(s, "\\", "/") s = strings.ReplaceAll(s, "\\", "/")
return strings.TrimSpace(fileNameSanitizeRegexp.ReplaceAllString(s, "_")) return strings.TrimSpace(fileNameSanitizeRegexp.ReplaceAllString(s, "_"))
} }
func copyUploadedLFSFilesIntoRepository(infos []uploadInfo, t *TemporaryUploadRepository, treePath string) error { func copyUploadedLFSFilesIntoRepository(infos []uploadInfo, t *TemporaryUploadRepository, treePath string) error {