Skip to content

Commit c72303b

Browse files
committed
webdav: path-escape lockroot
We ran in to an issue with various microsoft products accessing files over WebDAV which contain `%` characters in the name. The requests are all properly escaped -- e.g. the `%` is replaced with `%25`. Further the basic list functionality of the propfind responses contain encoded urls. The lock response/discovery includes the URL (lockroot) to the locked file. The existing implementation does not path escape that url. This seems to cause problems with the microsoft applications. When faced with the unencoded response, they try to lock again and fail. One explanation for this behaviour is that they maintain a table of locks indexed by encoded url. When the response from the server doesn't align with the URL they locked, the application fails. Update the lock discovery response code to escape the lockroot so that it matches everything else.
1 parent 8e2b117 commit c72303b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

webdav/xml.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"fmt"
1414
"io"
1515
"net/http"
16+
"net/url"
1617
"time"
1718

1819
// As of https://go-review.googlesource.com/#/c/12772/ which was submitted
@@ -87,6 +88,10 @@ func writeLockInfo(w io.Writer, token string, ld LockDetails) (int, error) {
8788
depth = "0"
8889
}
8990
timeout := ld.Duration / time.Second
91+
// PathEscape the root. Any URLs in this response body should match data on the wire
92+
// meaning if a request came in escaped (which it should have), it should go out that
93+
// way as well.
94+
root := url.PathEscape(ld.Root)
9095
return fmt.Fprintf(w, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"+
9196
"<D:prop xmlns:D=\"DAV:\"><D:lockdiscovery><D:activelock>\n"+
9297
" <D:locktype><D:write/></D:locktype>\n"+
@@ -97,7 +102,7 @@ func writeLockInfo(w io.Writer, token string, ld LockDetails) (int, error) {
97102
" <D:locktoken><D:href>%s</D:href></D:locktoken>\n"+
98103
" <D:lockroot><D:href>%s</D:href></D:lockroot>\n"+
99104
"</D:activelock></D:lockdiscovery></D:prop>",
100-
depth, ld.OwnerXML, timeout, escape(token), escape(ld.Root),
105+
depth, ld.OwnerXML, timeout, escape(token), escape(root),
101106
)
102107
}
103108

0 commit comments

Comments
 (0)