Skip to content

Commit 94da597

Browse files
committed
cmd/submit_test.go: Update test server to use unmodified filename
Following RFC 7578, Go 1.17+ strips the directory information in fileHeader.Filename. This change updates the test server to use Header["Content-Disposition"] for obtaining the unmodified filename for validating the submitted files directory tree in the request. This work builds on the PR opened by @QuLogic exercism#1066
1 parent ecd826d commit 94da597

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

cmd/submit_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"io/ioutil"
8+
"mime"
89
"net/http"
910
"net/http/httptest"
1011
"os"
@@ -561,7 +562,16 @@ func fakeSubmitServer(t *testing.T, submittedFiles map[string]string) *httptest.
561562
if err != nil {
562563
t.Fatal(err)
563564
}
564-
submittedFiles[fileHeader.Filename] = string(body)
565+
// Following RFC 7578, Go 1.17+ strips the directory information in fileHeader.Filename.
566+
// Validating the submitted files directory tree is important so Content-Disposition is used for
567+
// obtaining the unmodified filename.
568+
v := fileHeader.Header.Get("Content-Disposition")
569+
_, dispositionParams, err := mime.ParseMediaType(v)
570+
if err != nil {
571+
t.Fatalf("failed to obtain submitted filename from multipart header: %s", err.Error())
572+
}
573+
filename := dispositionParams["filename"]
574+
submittedFiles[filename] = string(body)
565575
}
566576

567577
fmt.Fprint(w, "{}")

0 commit comments

Comments
 (0)