feat(server): normalize etags from webdav to properly check for file changes

This commit is contained in:
perf3ct 2025-06-23 19:03:24 +00:00
parent 3d93c96c31
commit 472106a0f6
No known key found for this signature in database
GPG Key ID: 569C4EEC436F5232
2 changed files with 27 additions and 1 deletions

View File

@ -83,7 +83,13 @@ pub fn parse_propfind_response(xml_text: &str) -> Result<Vec<FileInfo>> {
resp.content_type = Some(text.trim().to_string());
}
"getetag" => {
resp.etag = Some(text.trim().to_string());
// Normalize ETag by removing quotes and weak ETag prefix
let etag = text.trim();
let normalized = etag
.trim_start_matches("W/")
.trim_matches('"')
.to_string();
resp.etag = Some(normalized);
}
"status" if in_propstat => {
// Check if status is 200 OK

View File

@ -182,6 +182,26 @@ fn test_etag_change_detection() {
assert_eq!(normalized_etag, old_etag);
}
#[test]
fn test_etag_normalization() {
// Test various ETag formats that WebDAV servers might return
let test_cases = vec![
("abc123", "abc123"), // Plain ETag
("\"abc123\"", "abc123"), // Quoted ETag
("W/\"abc123\"", "abc123"), // Weak ETag
("\"abc-123-def\"", "abc-123-def"), // Quoted with dashes
("W/\"abc-123-def\"", "abc-123-def"), // Weak ETag with dashes
];
for (input, expected) in test_cases {
let normalized = input
.trim_start_matches("W/")
.trim_matches('"');
assert_eq!(normalized, expected,
"Failed to normalize ETag: {} -> expected {}", input, expected);
}
}
#[test]
fn test_path_normalization() {
let test_paths = vec![