From 1f1f623292e7c1ede636f38135e8e7cffc1037f1 Mon Sep 17 00:00:00 2001 From: RoyVivat Date: Mon, 23 Mar 2026 15:50:59 -0700 Subject: [PATCH] Added non s3 scheme test. Removed .replace. --- litellm/utils.py | 2 +- tests/test_litellm/integrations/test_s3_v2.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/litellm/utils.py b/litellm/utils.py index 48b0bd87fc9..169ddc9715c 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -7406,7 +7406,7 @@ def get_logging_id(start_time, response_obj): # scheme and bucket, keeping only the object key to use as the log ID. if "://" in raw_id: after_scheme = raw_id.split("://", 1)[1] # "bucket/key" or "bucket" - safe_id = after_scheme.split("/", 1)[1].replace("/", "-") if "/" in after_scheme else "" + safe_id = after_scheme.split("/", 1)[1] if "/" in after_scheme else "" else: safe_id = raw_id response_id = "time-" + start_time.strftime("%H-%M-%S-%f") + "_" + safe_id diff --git a/tests/test_litellm/integrations/test_s3_v2.py b/tests/test_litellm/integrations/test_s3_v2.py index ce69dad3887..b5fa6f183cc 100644 --- a/tests/test_litellm/integrations/test_s3_v2.py +++ b/tests/test_litellm/integrations/test_s3_v2.py @@ -705,6 +705,16 @@ def test_get_logging_id_none_id_does_not_raise(): assert result.startswith("time-17-40-11-901585_") +def test_get_logging_id_non_s3_uri_scheme_stripped(): + """Non-S3 URI schemes (e.g. ftp://) are also stripped — lock in that behaviour.""" + start_time = datetime(2026, 3, 9, 17, 40, 11, 901585) + response_obj = {"id": "ftp://host/path/to/file"} + result = get_logging_id(start_time, response_obj) + assert "://" not in result + assert "host" not in result + assert result.startswith("time-17-40-11-901585_") + + def test_get_logging_id_s3_uri_safe_for_url_path(): """The sanitized log ID must be embeddable in an S3 object key URL without creating a malformed path.""" start_time = datetime(2026, 3, 9, 17, 40, 11, 901585)