git » go-net » commit 30db966

webdav: set 'getlastmodified' live property for directories

author H. İbrahim Güngör
2016-05-25 13:11:03 UTC
committer Nigel Tao
2016-05-27 00:43:53 UTC
parent dfd9ed699ea197b58a32e0d1dcfa2be66f127ec4

webdav: set 'getlastmodified' live property for directories

WebDAV clients can't sort folders by date because 'getlastmodified' live
property is not set.

Fixes golang/go#15334.

Change-Id: Ie56fcf8ae98173878e0972c0f9401151953334ff
Reviewed-on: https://go-review.googlesource.com/23422
Reviewed-by: Nigel Tao <nigeltao@golang.org>

webdav/prop.go +8 -1
webdav/prop_test.go +4 -0

diff --git a/webdav/prop.go b/webdav/prop.go
index ac6c65a..1459466 100644
--- a/webdav/prop.go
+++ b/webdav/prop.go
@@ -118,7 +118,14 @@ var liveProps = map[xml.Name]struct {
 	},
 	xml.Name{Space: "DAV:", Local: "getlastmodified"}: {
 		findFn: findLastModified,
-		dir:    false,
+		// http://webdav.org/specs/rfc4918.html#PROPERTY_getlastmodified
+		// suggests that getlastmodified should only apply to GETable
+		// resources, and this package does not support GET on directories.
+		//
+		// Nonetheless, some WebDAV clients expect child directories to be
+		// sortable by getlastmodified date, so this value is true, not false.
+		// See golang.org/issue/15334.
+		dir: true,
 	},
 	xml.Name{Space: "DAV:", Local: "creationdate"}: {
 		findFn: nil,
diff --git a/webdav/prop_test.go b/webdav/prop_test.go
index ee188ac..0834dc9 100644
--- a/webdav/prop_test.go
+++ b/webdav/prop_test.go
@@ -77,6 +77,7 @@ func TestMemPS(t *testing.T) {
 				{Space: "DAV:", Local: "resourcetype"},
 				{Space: "DAV:", Local: "displayname"},
 				{Space: "DAV:", Local: "supportedlock"},
+				{Space: "DAV:", Local: "getlastmodified"},
 			},
 		}, {
 			op:   "propname",
@@ -105,6 +106,9 @@ func TestMemPS(t *testing.T) {
 				}, {
 					XMLName:  xml.Name{Space: "DAV:", Local: "displayname"},
 					InnerXML: []byte("dir"),
+				}, {
+					XMLName:  xml.Name{Space: "DAV:", Local: "getlastmodified"},
+					InnerXML: nil, // Calculated during test.
 				}, {
 					XMLName:  xml.Name{Space: "DAV:", Local: "supportedlock"},
 					InnerXML: []byte(lockEntry),