diff --git a/webdav/webdav_test.go b/webdav/webdav_test.go
index 2baebe3c9..5499b334f 100644
--- a/webdav/webdav_test.go
+++ b/webdav/webdav_test.go
@@ -21,21 +21,21 @@ import (
"testing"
)
+// createLockBody comes from the example in Section 9.10.7.
+const createLockBody = `
+
+
+
+
+ http://example.org/~ejw/contact.html
+
+
+`
+
// TODO: add tests to check XML responses with the expected prefix path
func TestPrefix(t *testing.T) {
const dst, blah = "Destination", "blah blah blah"
- // createLockBody comes from the example in Section 9.10.7.
- const createLockBody = `
-
-
-
-
- http://example.org/~ejw/contact.html
-
-
- `
-
do := func(method, urlStr string, body string, wantStatusCode int, headers ...string) (http.Header, error) {
var bodyReader io.Reader
if body != "" {
@@ -347,3 +347,92 @@ func TestFilenameEscape(t *testing.T) {
}
}
}
+
+func TestLockrootEscape(t *testing.T) {
+ lockrootRe := regexp.MustCompile(`([^<]*)`)
+ do := func(urlStr string) (string, error) {
+ bodyReader := strings.NewReader(createLockBody)
+ req, err := http.NewRequest("LOCK", urlStr, bodyReader)
+ if err != nil {
+ return "", err
+ }
+ res, err := http.DefaultClient.Do(req)
+ if err != nil {
+ return "", err
+ }
+ defer res.Body.Close()
+
+ b, err := ioutil.ReadAll(res.Body)
+ if err != nil {
+ return "", err
+ }
+ lockrootMatch := lockrootRe.FindStringSubmatch(string(b))
+ if len(lockrootMatch) != 2 {
+ return "", errors.New("D:lockroot not found")
+ }
+
+ return lockrootMatch[1], nil
+ }
+
+ testCases := []struct {
+ name, wantLockroot string
+ }{{
+ name: `/foo%bar`,
+ wantLockroot: `/foo%25bar`,
+ }, {
+ name: `/こんにちわ世界`,
+ wantLockroot: `/%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%82%8F%E4%B8%96%E7%95%8C`,
+ }, {
+ name: `/Program Files/`,
+ wantLockroot: `/Program%20Files/`,
+ }, {
+ name: `/go+lang`,
+ wantLockroot: `/go+lang`,
+ }, {
+ name: `/go&lang`,
+ wantLockroot: `/go&lang`,
+ }, {
+ name: `/go\n"+
"\n"+
" \n"+
@@ -97,7 +103,7 @@ func writeLockInfo(w io.Writer, token string, ld LockDetails) (int, error) {
" %s\n"+
" %s\n"+
"",
- depth, ld.OwnerXML, timeout, escape(token), escape(ld.Root),
+ depth, ld.OwnerXML, timeout, escape(token), escape(root),
)
}