summaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/net/webdav/prop.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/golang.org/x/net/webdav/prop.go')
-rw-r--r--vendor/golang.org/x/net/webdav/prop.go83
1 files changed, 53 insertions, 30 deletions
diff --git a/vendor/golang.org/x/net/webdav/prop.go b/vendor/golang.org/x/net/webdav/prop.go
index 145946637..e36a3b31d 100644
--- a/vendor/golang.org/x/net/webdav/prop.go
+++ b/vendor/golang.org/x/net/webdav/prop.go
@@ -5,6 +5,7 @@
package webdav
import (
+ "bytes"
"encoding/xml"
"fmt"
"io"
@@ -13,6 +14,8 @@ import (
"os"
"path/filepath"
"strconv"
+
+ "golang.org/x/net/context"
)
// Proppatch describes a property update instruction as defined in RFC 4918.
@@ -100,23 +103,23 @@ type DeadPropsHolder interface {
var liveProps = map[xml.Name]struct {
// findFn implements the propfind function of this property. If nil,
// it indicates a hidden property.
- findFn func(FileSystem, LockSystem, string, os.FileInfo) (string, error)
+ findFn func(context.Context, FileSystem, LockSystem, string, os.FileInfo) (string, error)
// dir is true if the property applies to directories.
dir bool
}{
- xml.Name{Space: "DAV:", Local: "resourcetype"}: {
+ {Space: "DAV:", Local: "resourcetype"}: {
findFn: findResourceType,
dir: true,
},
- xml.Name{Space: "DAV:", Local: "displayname"}: {
+ {Space: "DAV:", Local: "displayname"}: {
findFn: findDisplayName,
dir: true,
},
- xml.Name{Space: "DAV:", Local: "getcontentlength"}: {
+ {Space: "DAV:", Local: "getcontentlength"}: {
findFn: findContentLength,
dir: false,
},
- xml.Name{Space: "DAV:", Local: "getlastmodified"}: {
+ {Space: "DAV:", Local: "getlastmodified"}: {
findFn: findLastModified,
// http://webdav.org/specs/rfc4918.html#PROPERTY_getlastmodified
// suggests that getlastmodified should only apply to GETable
@@ -127,19 +130,19 @@ var liveProps = map[xml.Name]struct {
// See golang.org/issue/15334.
dir: true,
},
- xml.Name{Space: "DAV:", Local: "creationdate"}: {
+ {Space: "DAV:", Local: "creationdate"}: {
findFn: nil,
dir: false,
},
- xml.Name{Space: "DAV:", Local: "getcontentlanguage"}: {
+ {Space: "DAV:", Local: "getcontentlanguage"}: {
findFn: nil,
dir: false,
},
- xml.Name{Space: "DAV:", Local: "getcontenttype"}: {
+ {Space: "DAV:", Local: "getcontenttype"}: {
findFn: findContentType,
dir: false,
},
- xml.Name{Space: "DAV:", Local: "getetag"}: {
+ {Space: "DAV:", Local: "getetag"}: {
findFn: findETag,
// findETag implements ETag as the concatenated hex values of a file's
// modification time and size. This is not a reliable synchronization
@@ -150,8 +153,8 @@ var liveProps = map[xml.Name]struct {
// TODO: The lockdiscovery property requires LockSystem to list the
// active locks on a resource.
- xml.Name{Space: "DAV:", Local: "lockdiscovery"}: {},
- xml.Name{Space: "DAV:", Local: "supportedlock"}: {
+ {Space: "DAV:", Local: "lockdiscovery"}: {},
+ {Space: "DAV:", Local: "supportedlock"}: {
findFn: findSupportedLock,
dir: true,
},
@@ -163,8 +166,8 @@ var liveProps = map[xml.Name]struct {
//
// Each Propstat has a unique status and each property name will only be part
// of one Propstat element.
-func props(fs FileSystem, ls LockSystem, name string, pnames []xml.Name) ([]Propstat, error) {
- f, err := fs.OpenFile(name, os.O_RDONLY, 0)
+func props(ctx context.Context, fs FileSystem, ls LockSystem, name string, pnames []xml.Name) ([]Propstat, error) {
+ f, err := fs.OpenFile(ctx, name, os.O_RDONLY, 0)
if err != nil {
return nil, err
}
@@ -193,7 +196,7 @@ func props(fs FileSystem, ls LockSystem, name string, pnames []xml.Name) ([]Prop
}
// Otherwise, it must either be a live property or we don't know it.
if prop := liveProps[pn]; prop.findFn != nil && (prop.dir || !isDir) {
- innerXML, err := prop.findFn(fs, ls, name, fi)
+ innerXML, err := prop.findFn(ctx, fs, ls, name, fi)
if err != nil {
return nil, err
}
@@ -211,8 +214,8 @@ func props(fs FileSystem, ls LockSystem, name string, pnames []xml.Name) ([]Prop
}
// Propnames returns the property names defined for resource name.
-func propnames(fs FileSystem, ls LockSystem, name string) ([]xml.Name, error) {
- f, err := fs.OpenFile(name, os.O_RDONLY, 0)
+func propnames(ctx context.Context, fs FileSystem, ls LockSystem, name string) ([]xml.Name, error) {
+ f, err := fs.OpenFile(ctx, name, os.O_RDONLY, 0)
if err != nil {
return nil, err
}
@@ -251,8 +254,8 @@ func propnames(fs FileSystem, ls LockSystem, name string) ([]xml.Name, error) {
// returned if they are named in 'include'.
//
// See http://www.webdav.org/specs/rfc4918.html#METHOD_PROPFIND
-func allprop(fs FileSystem, ls LockSystem, name string, include []xml.Name) ([]Propstat, error) {
- pnames, err := propnames(fs, ls, name)
+func allprop(ctx context.Context, fs FileSystem, ls LockSystem, name string, include []xml.Name) ([]Propstat, error) {
+ pnames, err := propnames(ctx, fs, ls, name)
if err != nil {
return nil, err
}
@@ -266,12 +269,12 @@ func allprop(fs FileSystem, ls LockSystem, name string, include []xml.Name) ([]P
pnames = append(pnames, pn)
}
}
- return props(fs, ls, name, pnames)
+ return props(ctx, fs, ls, name, pnames)
}
// Patch patches the properties of resource name. The return values are
// constrained in the same manner as DeadPropsHolder.Patch.
-func patch(fs FileSystem, ls LockSystem, name string, patches []Proppatch) ([]Propstat, error) {
+func patch(ctx context.Context, fs FileSystem, ls LockSystem, name string, patches []Proppatch) ([]Propstat, error) {
conflict := false
loop:
for _, patch := range patches {
@@ -302,7 +305,7 @@ loop:
return makePropstats(pstatForbidden, pstatFailedDep), nil
}
- f, err := fs.OpenFile(name, os.O_RDWR, 0)
+ f, err := fs.OpenFile(ctx, name, os.O_RDWR, 0)
if err != nil {
return nil, err
}
@@ -333,31 +336,51 @@ loop:
return []Propstat{pstat}, nil
}
-func findResourceType(fs FileSystem, ls LockSystem, name string, fi os.FileInfo) (string, error) {
+func escapeXML(s string) string {
+ for i := 0; i < len(s); i++ {
+ // As an optimization, if s contains only ASCII letters, digits or a
+ // few special characters, the escaped value is s itself and we don't
+ // need to allocate a buffer and convert between string and []byte.
+ switch c := s[i]; {
+ case c == ' ' || c == '_' ||
+ ('+' <= c && c <= '9') || // Digits as well as + , - . and /
+ ('A' <= c && c <= 'Z') ||
+ ('a' <= c && c <= 'z'):
+ continue
+ }
+ // Otherwise, go through the full escaping process.
+ var buf bytes.Buffer
+ xml.EscapeText(&buf, []byte(s))
+ return buf.String()
+ }
+ return s
+}
+
+func findResourceType(ctx context.Context, fs FileSystem, ls LockSystem, name string, fi os.FileInfo) (string, error) {
if fi.IsDir() {
return `<D:collection xmlns:D="DAV:"/>`, nil
}
return "", nil
}
-func findDisplayName(fs FileSystem, ls LockSystem, name string, fi os.FileInfo) (string, error) {
+func findDisplayName(ctx context.Context, fs FileSystem, ls LockSystem, name string, fi os.FileInfo) (string, error) {
if slashClean(name) == "/" {
// Hide the real name of a possibly prefixed root directory.
return "", nil
}
- return fi.Name(), nil
+ return escapeXML(fi.Name()), nil
}
-func findContentLength(fs FileSystem, ls LockSystem, name string, fi os.FileInfo) (string, error) {
+func findContentLength(ctx context.Context, fs FileSystem, ls LockSystem, name string, fi os.FileInfo) (string, error) {
return strconv.FormatInt(fi.Size(), 10), nil
}
-func findLastModified(fs FileSystem, ls LockSystem, name string, fi os.FileInfo) (string, error) {
+func findLastModified(ctx context.Context, fs FileSystem, ls LockSystem, name string, fi os.FileInfo) (string, error) {
return fi.ModTime().Format(http.TimeFormat), nil
}
-func findContentType(fs FileSystem, ls LockSystem, name string, fi os.FileInfo) (string, error) {
- f, err := fs.OpenFile(name, os.O_RDONLY, 0)
+func findContentType(ctx context.Context, fs FileSystem, ls LockSystem, name string, fi os.FileInfo) (string, error) {
+ f, err := fs.OpenFile(ctx, name, os.O_RDONLY, 0)
if err != nil {
return "", err
}
@@ -379,14 +402,14 @@ func findContentType(fs FileSystem, ls LockSystem, name string, fi os.FileInfo)
return ctype, err
}
-func findETag(fs FileSystem, ls LockSystem, name string, fi os.FileInfo) (string, error) {
+func findETag(ctx context.Context, fs FileSystem, ls LockSystem, name string, fi os.FileInfo) (string, error) {
// The Apache http 2.4 web server by default concatenates the
// modification time and size of a file. We replicate the heuristic
// with nanosecond granularity.
return fmt.Sprintf(`"%x%x"`, fi.ModTime().UnixNano(), fi.Size()), nil
}
-func findSupportedLock(fs FileSystem, ls LockSystem, name string, fi os.FileInfo) (string, error) {
+func findSupportedLock(ctx context.Context, fs FileSystem, ls LockSystem, name string, fi os.FileInfo) (string, error) {
return `` +
`<D:lockentry xmlns:D="DAV:">` +
`<D:lockscope><D:exclusive/></D:lockscope>` +