fix: handle urlsafe base64 in decoder

This commit is contained in:
sankalp committed 2026-10-04 07:24:20 +05:45
1 parent 8022f37ae2
commit 0e1db2bd94
1 file changed
+6 -2
+6 -2
View File
@@ -182,6 +182,10 @@ def _coerce(cls: type[T], data: Any) -> T:
def decode_base64_content(encoded_content: str) -> str:
"""Decode base64 content, falling back to the raw string (DecodeBase64Content)."""
try:
return base64.b64decode(encoded_content).decode("utf-8")
except (ValueError, TypeError):
# Try standard base64 first, then urlsafe
try:
return base64.b64decode(encoded_content, validate=False).decode("utf-8")
except Exception:
return base64.urlsafe_b64decode(encoded_content + "=" * (-len(encoded_content) % 4)).decode("utf-8")
except (ValueError, TypeError, Exception):
return encoded_content