From 1617be3aee3d61cf6e479b6084e3ae783dd0b51d Mon Sep 17 00:00:00 2001 From: 1sonhador <1sonhador@gmail.com> Date: Thu, 2 Jul 2026 23:11:15 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20detect=20WebDAV=20year=20folder=20anywhe?= =?UTF-8?q?re=20in=20path=20(Faturas/2025/=E2=80=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/forwarder/webdav/client.py | 9 +++------ tests/test_webdav.py | 6 +++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/forwarder/webdav/client.py b/src/forwarder/webdav/client.py index a6e47c8..7aa342a 100644 --- a/src/forwarder/webdav/client.py +++ b/src/forwarder/webdav/client.py @@ -95,12 +95,9 @@ def parse_webdav_message_key(message_key: str) -> str | None: def webdav_year_folder(relative_path: str) -> str | None: - parts = [part for part in relative_path.strip("/").split("/") if part] - if not parts: - return None - head = parts[0] - if len(head) == 4 and head.isdigit(): - return head + for part in relative_path.strip("/").split("/"): + if len(part) == 4 and part.isdigit(): + return part return None diff --git a/tests/test_webdav.py b/tests/test_webdav.py index b9ebfc4..e21a59a 100644 --- a/tests/test_webdav.py +++ b/tests/test_webdav.py @@ -74,9 +74,9 @@ def test_webdav_message_key_roundtrip(): def test_webdav_path_matches_min_year(): assert webdav_path_matches_min_year("2025/invoice.pdf", 2025) - assert webdav_path_matches_min_year("2026/a.pdf", 2025) - assert webdav_path_matches_min_year("2027/future.pdf", 2025) - assert not webdav_path_matches_min_year("2024/old.pdf", 2025) + assert webdav_path_matches_min_year("Faturas/2026/08/a.pdf", 2025) + assert webdav_path_matches_min_year("Faturas/2027/future.pdf", 2025) + assert not webdav_path_matches_min_year("Faturas/2024/old.pdf", 2025) assert not webdav_path_matches_min_year("misc/file.pdf", 2025) assert webdav_path_matches_min_year("2024/old.pdf", None)