Skip to content

Commit 525aad0

Browse files
authored
Fix parsing webdav creationdate attribute (apache) (#13)
Fix parsing webdav creationdate attribute (apache)
1 parent bfd4772 commit 525aad0

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

app/src/main/java/com/phpbg/easysync/dav/WebDavService.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import java.nio.file.Paths
5858
import java.nio.file.StandardCopyOption
5959
import java.nio.file.attribute.FileTime
6060
import java.time.ZonedDateTime
61+
import java.time.format.DateTimeFormatter.ISO_DATE_TIME
6162
import java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME
6263
import java.util.concurrent.TimeUnit
6364

@@ -334,7 +335,7 @@ class WebDavService(
334335
"creationdate" -> resource = resource.copy(
335336
creationdate = ZonedDateTime.parse(
336337
text,
337-
RFC_1123_DATE_TIME
338+
ISO_DATE_TIME // encoded in rfc3339 according to webdav spec
338339
).toInstant()
339340
)
340341

app/src/test/java/com/phpbg/easysync/dav/ParseTest.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ class ParseTest {
5656
assert(expected == res.first())
5757
}
5858

59+
@Test
60+
fun propfind_apache_file_works() {
61+
val stream = this.javaClass.classLoader.getResourceAsStream("file_apache.xml")
62+
val rootPath = RootPath("https://foo")
63+
val res = WebDavService.parsePropfind(stream.reader(), rootPath)
64+
val expected = Resource(
65+
rootPath = rootPath,
66+
href = "/remote.php/dav/files/foouser/DCIM/bar.jpg",
67+
creationdate = ZonedDateTime.parse("2024-01-08T19:14:11Z", DateTimeFormatter.ISO_DATE_TIME).toInstant(),
68+
getlastmodified = ZonedDateTime.parse("Mon, 08 Jan 2024 19:14:11 GMT", DateTimeFormatter.RFC_1123_DATE_TIME).toInstant(),
69+
isCollection = false,
70+
getetag = "\"bacfa6f123dee073dc9e20774470681a\"",
71+
getcontentlength = "425623",
72+
getcontenttype = "image/jpeg"
73+
)
74+
assert(expected == res.first())
75+
}
76+
5977
@Test
6078
fun propfind_uri_decode_works() {
6179
val stream = this.javaClass.classLoader.getResourceAsStream("file_uri_encoded.xml")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<d:multistatus xmlns:d="DAV:">
2+
<d:response>
3+
<d:href>/remote.php/dav/files/foouser/DCIM/bar.jpg</d:href>
4+
<d:propstat>
5+
<d:prop>
6+
<d:creationdate>2024-01-08T19:14:11Z</d:creationdate>
7+
<d:getlastmodified>Mon, 08 Jan 2024 19:14:11 GMT</d:getlastmodified>
8+
<d:getcontentlength>425623</d:getcontentlength>
9+
<d:resourcetype/>
10+
<d:getetag>&quot;bacfa6f123dee073dc9e20774470681a&quot;</d:getetag>
11+
<d:getcontenttype>image/jpeg</d:getcontenttype>
12+
</d:prop>
13+
<d:status>HTTP/1.1 200 OK</d:status>
14+
</d:propstat>
15+
</d:response>
16+
</d:multistatus>

0 commit comments

Comments
 (0)