Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ func runDownload(cfg config.Config, flags *pflag.FlagSet, args []string) error {

// TODO: if there's a collision, interactively resolve (show diff, ask if overwrite).
// TODO: handle --force flag to overwrite without asking.

// Rewrite paths submitted with an older, buggy client where the Windows path is being treated as part of the filename.
file = strings.Replace(file, "\\", "/", -1)

relativePath := filepath.FromSlash(file)
dir := filepath.Join(solution.Dir, filepath.Dir(relativePath))
os.MkdirAll(dir, os.FileMode(0755))
Expand Down
19 changes: 19 additions & 0 deletions cmd/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ func fakeDownloadServer(requestor, teamSlug string) *httptest.Server {
fmt.Fprint(w, "this is a special file")
})

mux.HandleFunc("/\\with-leading-backslash.txt", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "with backslash in name")
})
mux.HandleFunc("/\\with\\backslashes\\in\\path.txt", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "with backslash in path")
})

mux.HandleFunc("/with-leading-slash.txt", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "this has a slash")
})
Expand Down Expand Up @@ -220,6 +227,16 @@ func assertDownloadedCorrectFiles(t *testing.T, targetDir string) {
path: filepath.Join(targetDir, "bogus-track", "bogus-exercise", "with-leading-slash.txt"),
contents: "this has a slash",
},
{
desc: "a file with a leading backslash",
path: filepath.Join(targetDir, "bogus-track", "bogus-exercise", "with-leading-backslash.txt"),
contents: "with backslash in name",
},
{
desc: "a file with backslashes in path",
path: filepath.Join(targetDir, "bogus-track", "bogus-exercise", "with", "backslashes", "in", "path.txt"),
contents: "with backslash in path",
},
}

for _, file := range expectedFiles {
Expand Down Expand Up @@ -259,6 +276,8 @@ const payloadTemplate = `
"subdir/file-2.txt",
"special-char-filename#.txt",
"/with-leading-slash.txt",
"\\with-leading-backslash.txt",
"\\with\\backslashes\\in\\path.txt",
"file-3.txt"
],
"iteration": {
Expand Down