Skip to content

Commit 4389eb8

Browse files
committed
🩹 (sync/memorious) Tweak strip prefix func
1 parent f0b6f50 commit 4389eb8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

leakrfc/sync/memorious.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,12 @@ def _func(data: dict[str, Any]) -> str:
138138

139139

140140
def get_file_name_strip_func(strip_prefix: str) -> Callable:
141+
strip_prefix = strip_prefix.strip("/")
142+
141143
def _func(data: dict[str, Any]) -> str:
142-
return get_file_key(data)[len(strip_prefix) :].strip("/")
144+
key = get_file_key(data)
145+
if key.startswith(strip_prefix):
146+
key = key[len(strip_prefix) :].strip("/")
147+
return key
143148

144149
return _func

tests/test_sync.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,8 @@ def get_key(data):
6868
get_file_name_strip_func("en/request")(data)
6969
== "14928/response/55317/attach/5/Communication from the Commission SG 2009 D 51604.pdf"
7070
)
71+
assert (
72+
get_file_name_strip_func("foo/bar")(data)
73+
== "en/request/14928/response/55317/attach/5/Communication from the Commission SG 2009 D 51604.pdf"
74+
)
7175
assert get_file_name_templ_func("{{ headers.Server }}.pdf")(data) == "nginx.pdf"

0 commit comments

Comments
 (0)