Strip encoded attachment metadata delimiters

This commit is contained in:
TerminallyLazy 2026-08-10 21:08:47 -04:00 committed by Alessandro
parent e9d5274064
commit efdb5f4aca
2 changed files with 10 additions and 0 deletions

View file

@ -88,6 +88,7 @@ def _attachment_log_metadata(attachments: list[str]) -> dict[str, list[str]]:
continue
path = parsed.path if parsed.scheme else normalized.split("?", 1)[0].split("#", 1)[0]
path = unquote(path).replace("\\", "/")
path = path.split("?", 1)[0].split("#", 1)[0]
if path.endswith("/"):
continue
name = path.rstrip("/").rsplit("/", 1)[-1]

View file

@ -43,6 +43,15 @@ def test_attachment_log_metadata_decodes_encoded_separators() -> None:
) == {"attachments": ["secret.png", "secret.png"]}
def test_attachment_log_metadata_strips_encoded_query_and_fragment_suffixes() -> None:
assert _attachment_log_metadata(
[
"https://host/report%3Ftoken%3Dsecret.png",
"https://host/image%23private-fragment.png",
]
) == {"attachments": ["report", "image"]}
class RecordingLog:
def __init__(self) -> None:
self.calls: list[dict[str, object]] = []