From 0e1db2bd948f4d8273a5a98a00c27eadf2acc890 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Sun, 4 Oct 2026 07:24:20 +0545 Subject: [PATCH] fix: handle urlsafe base64 in decoder --- nepali_payment/helpers.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nepali_payment/helpers.py b/nepali_payment/helpers.py index 0370562..4cb6d86 100644 --- a/nepali_payment/helpers.py +++ b/nepali_payment/helpers.py @@ -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