Browse Source

webdav: add trailing slash on directories

Fixes golang/go#29858

Change-Id: I7bd8357a7def7daab1fd6357a888ff4e676a1bee
GitHub-Last-Rev: a6dc776fa3aad595643943dcff88efcf152d6be1
GitHub-Pull-Request: golang/net#32
Reviewed-on: https://go-review.googlesource.com/c/163863
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Mickael KERJEAN 6 years ago
parent
commit
c95aed5357
2 changed files with 6 additions and 2 deletions
  1. 5 1
      webdav/webdav.go
  2. 1 1
      webdav/webdav_test.go

+ 5 - 1
webdav/webdav.go

@@ -556,7 +556,11 @@ func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) (status
 		if err != nil {
 			return err
 		}
-		return mw.write(makePropstatResponse(path.Join(h.Prefix, reqPath), pstats))
+		href := path.Join(h.Prefix, reqPath)
+		if info.IsDir() {
+			href += "/"
+		}
+		return mw.write(makePropstatResponse(href, pstats))
 	}
 
 	walkErr := walkFS(ctx, h.FileSystem, depth, reqPath, fi, walkFn)

+ 1 - 1
webdav/webdav_test.go

@@ -284,7 +284,7 @@ func TestFilenameEscape(t *testing.T) {
 		wantDisplayName: `こんにちわ世界`,
 	}, {
 		name:            `/Program Files/`,
-		wantHref:        `/Program%20Files`,
+		wantHref:        `/Program%20Files/`,
 		wantDisplayName: `Program Files`,
 	}, {
 		name:            `/go+lang`,