Skip to content

Commit e6277a7

Browse files
author
Katrina Owen
authored
Merge pull request #721 from exercism/backslash-paths
Handle windows filepaths that accidentally got submitted to the server
2 parents 536c25f + 65529d3 commit e6277a7

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

cmd/download.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ func runDownload(cfg config.Config, flags *pflag.FlagSet, args []string) error {
199199

200200
// TODO: if there's a collision, interactively resolve (show diff, ask if overwrite).
201201
// TODO: handle --force flag to overwrite without asking.
202+
203+
// Rewrite paths submitted with an older, buggy client where the Windows path is being treated as part of the filename.
204+
file = strings.Replace(file, "\\", "/", -1)
205+
202206
relativePath := filepath.FromSlash(file)
203207
dir := filepath.Join(solution.Dir, filepath.Dir(relativePath))
204208
os.MkdirAll(dir, os.FileMode(0755))

cmd/download_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ func fakeDownloadServer(requestor, teamSlug string) *httptest.Server {
170170
fmt.Fprint(w, "this is a special file")
171171
})
172172

173+
mux.HandleFunc("/\\with-leading-backslash.txt", func(w http.ResponseWriter, r *http.Request) {
174+
fmt.Fprint(w, "with backslash in name")
175+
})
176+
mux.HandleFunc("/\\with\\backslashes\\in\\path.txt", func(w http.ResponseWriter, r *http.Request) {
177+
fmt.Fprint(w, "with backslash in path")
178+
})
179+
173180
mux.HandleFunc("/with-leading-slash.txt", func(w http.ResponseWriter, r *http.Request) {
174181
fmt.Fprint(w, "this has a slash")
175182
})
@@ -220,6 +227,16 @@ func assertDownloadedCorrectFiles(t *testing.T, targetDir string) {
220227
path: filepath.Join(targetDir, "bogus-track", "bogus-exercise", "with-leading-slash.txt"),
221228
contents: "this has a slash",
222229
},
230+
{
231+
desc: "a file with a leading backslash",
232+
path: filepath.Join(targetDir, "bogus-track", "bogus-exercise", "with-leading-backslash.txt"),
233+
contents: "with backslash in name",
234+
},
235+
{
236+
desc: "a file with backslashes in path",
237+
path: filepath.Join(targetDir, "bogus-track", "bogus-exercise", "with", "backslashes", "in", "path.txt"),
238+
contents: "with backslash in path",
239+
},
223240
}
224241

225242
for _, file := range expectedFiles {
@@ -259,6 +276,8 @@ const payloadTemplate = `
259276
"subdir/file-2.txt",
260277
"special-char-filename#.txt",
261278
"/with-leading-slash.txt",
279+
"\\with-leading-backslash.txt",
280+
"\\with\\backslashes\\in\\path.txt",
262281
"file-3.txt"
263282
],
264283
"iteration": {

0 commit comments

Comments
 (0)