From cc34779294c3e128d385ef442a13307b8a553a64 Mon Sep 17 00:00:00 2001 From: CrispyBaguette Date: Mon, 8 Jan 2024 07:37:17 +0100 Subject: [PATCH] Move query escaping to multipartwriter --- main.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 91a7e96..087302a 100644 --- a/main.go +++ b/main.go @@ -41,30 +41,32 @@ func NewIpfsMultipartWriter(w io.Writer) *IpfsMultipartWriter { func (w *IpfsMultipartWriter) CreateIpfsDirectoryPart(name string) (io.Writer, error) { h := make(textproto.MIMEHeader) - h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, name)) + encodedName := url.QueryEscape(name) + h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, encodedName)) h.Set("Content-Type", "application/x-directory") return w.CreatePart(h) } func (w *IpfsMultipartWriter) CreateIpfsFilePart(name string) (io.Writer, error) { h := make(textproto.MIMEHeader) - h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, escapeQuotes(name))) + encodedName := url.QueryEscape(name) + h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, escapeQuotes(encodedName))) h.Set("Content-Type", "application/octet-stream") return w.CreatePart(h) } func (w *IpfsMultipartWriter) CreateIpfsAbsFilePart(name, absPath string) (io.Writer, error) { h := make(textproto.MIMEHeader) + encodedName := url.QueryEscape(name) h.Set("AbsPath", absPath) - h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, escapeQuotes(name))) + h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, escapeQuotes(encodedName))) h.Set("Content-Type", "application/octet-stream") return w.CreatePart(h) } func main() { - githubactions.Infof("Checking inputs...") + githubactions.Debugf("Checking inputs") - // Check inputs path := githubactions.GetInput("path_to_add") if path == "" { githubactions.Fatalf("Missing: path_to_add") @@ -95,7 +97,7 @@ func main() { githubactions.Fatalf("%v is not a directory", path) } - githubactions.Infof("Inputs OK") + githubactions.Debugf("Inputs OK") body, writer := io.Pipe() @@ -128,7 +130,7 @@ func main() { } relPath, _ := filepath.Rel(path, innerPath) - w, err := mwriter.CreateIpfsFilePart(url.QueryEscape(fmt.Sprintf("/%v", relPath))) + w, err := mwriter.CreateIpfsFilePart(relPath) if err != nil { return err }