fix: webdav propfind dir with slash (#42)

This commit is contained in:
sigoden 2022-06-15 20:24:53 +08:00 committed by GitHub
parent 3c4bb77023
commit c7d42a3f1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -812,9 +812,16 @@ struct PathItem {
} }
impl PathItem { impl PathItem {
pub fn is_dir(&self) -> bool {
self.path_type == PathType::Dir || self.path_type == PathType::SymlinkDir
}
pub fn to_dav_xml(&self, prefix: &str) -> String { pub fn to_dav_xml(&self, prefix: &str) -> String {
let mtime = Utc.timestamp_millis(self.mtime as i64).to_rfc2822(); let mtime = Utc.timestamp_millis(self.mtime as i64).to_rfc2822();
let href = encode_uri(&format!("{}{}", prefix, &self.name)); let mut href = encode_uri(&format!("{}{}", prefix, &self.name));
if self.is_dir() && !href.ends_with('/') {
href.push('/');
}
let displayname = escape_str_pcdata(self.base_name()); let displayname = escape_str_pcdata(self.base_name());
match self.path_type { match self.path_type {
PathType::Dir | PathType::SymlinkDir => format!( PathType::Dir | PathType::SymlinkDir => format!(

View file

@ -10,7 +10,7 @@ fn propfind_dir(server: TestServer) -> Result<(), Error> {
let resp = fetch!(b"PROPFIND", format!("{}dira", server.url())).send()?; let resp = fetch!(b"PROPFIND", format!("{}dira", server.url())).send()?;
assert_eq!(resp.status(), 207); assert_eq!(resp.status(), 207);
let body = resp.text()?; let body = resp.text()?;
assert!(body.contains("<D:href>/dira</D:href>")); assert!(body.contains("<D:href>/dira/</D:href>"));
assert!(body.contains("<D:displayname>dira</D:displayname>")); assert!(body.contains("<D:displayname>dira</D:displayname>"));
for f in FILES { for f in FILES {
assert!(body.contains(&format!("<D:href>/dira/{}</D:href>", utils::encode_uri(f)))); assert!(body.contains(&format!("<D:href>/dira/{}</D:href>", utils::encode_uri(f))));
@ -29,7 +29,7 @@ fn propfind_dir_depth0(server: TestServer) -> Result<(), Error> {
.send()?; .send()?;
assert_eq!(resp.status(), 207); assert_eq!(resp.status(), 207);
let body = resp.text()?; let body = resp.text()?;
assert!(body.contains("<D:href>/dira</D:href>")); assert!(body.contains("<D:href>/dira/</D:href>"));
assert!(body.contains("<D:displayname>dira</D:displayname>")); assert!(body.contains("<D:displayname>dira</D:displayname>"));
assert_eq!( assert_eq!(
body.lines() body.lines()