diff --git a/src/webdav_xml_parser.rs b/src/webdav_xml_parser.rs index 6fcc17d..ac6a737 100644 --- a/src/webdav_xml_parser.rs +++ b/src/webdav_xml_parser.rs @@ -237,7 +237,7 @@ mod tests { assert_eq!(file.name, "test.pdf"); assert_eq!(file.size, 1024); assert_eq!(file.mime_type, "application/pdf"); - assert_eq!(file.etag, "\"abc123\""); + assert_eq!(file.etag, "abc123"); assert!(!file.is_directory); } @@ -306,6 +306,7 @@ mod tests { assert_eq!(file.name, "report.pdf"); assert_eq!(file.path, "/remote.php/dav/files/admin/Documents/report.pdf"); assert_eq!(file.size, 2048000); + assert_eq!(file.etag, "pdf123"); // ETag should be normalized (quotes removed) assert!(file.last_modified.is_some()); } diff --git a/tests/webdav_sync_tests.rs b/tests/webdav_sync_tests.rs index 71e1954..ed343ab 100644 --- a/tests/webdav_sync_tests.rs +++ b/tests/webdav_sync_tests.rs @@ -202,6 +202,32 @@ fn test_etag_normalization() { } } +#[test] +fn test_etag_comparison_fixes_duplicate_downloads() { + // This test demonstrates how ETag normalization prevents unnecessary downloads + + // Simulate a WebDAV server that returns quoted ETags + let server_etag = "\"file-hash-123\""; + + // Before fix: stored ETag would have quotes, server ETag would have quotes + // After fix: both should be normalized (no quotes) + let normalized_server = server_etag.trim_start_matches("W/").trim_matches('"'); + let normalized_stored = "file-hash-123"; // What would be stored after normalization + + // These should match after normalization, preventing redownload + assert_eq!(normalized_server, normalized_stored, + "Normalized ETags should match to prevent unnecessary redownloads"); + + // Demonstrate the issue that was fixed + let old_behavior_would_mismatch = (server_etag != normalized_stored); + assert!(old_behavior_would_mismatch, + "Before fix: quoted vs unquoted ETags would cause unnecessary downloads"); + + let new_behavior_matches = (normalized_server == normalized_stored); + assert!(new_behavior_matches, + "After fix: normalized ETags match, preventing unnecessary downloads"); +} + #[test] fn test_path_normalization() { let test_paths = vec![