Skip to content

Commit

Permalink
🩹 (sync/memorious) Tweak strip prefix func
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwoerpel committed Jan 23, 2025
1 parent f0b6f50 commit 4389eb8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion leakrfc/sync/memorious.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ def _func(data: dict[str, Any]) -> str:


def get_file_name_strip_func(strip_prefix: str) -> Callable:
strip_prefix = strip_prefix.strip("/")

def _func(data: dict[str, Any]) -> str:
return get_file_key(data)[len(strip_prefix) :].strip("/")
key = get_file_key(data)
if key.startswith(strip_prefix):
key = key[len(strip_prefix) :].strip("/")
return key

return _func
4 changes: 4 additions & 0 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@ def get_key(data):
get_file_name_strip_func("en/request")(data)
== "14928/response/55317/attach/5/Communication from the Commission SG 2009 D 51604.pdf"
)
assert (
get_file_name_strip_func("foo/bar")(data)
== "en/request/14928/response/55317/attach/5/Communication from the Commission SG 2009 D 51604.pdf"
)
assert get_file_name_templ_func("{{ headers.Server }}.pdf")(data) == "nginx.pdf"

0 comments on commit 4389eb8

Please sign in to comment.