Handle malformed base64 HAR content (#10)

This commit is contained in:
Sheroy Cooper authored and GitHub committed 2026-07-26 21:34:20 +05:30
1 parent 847e54d922
commit 8cf998ac0b
2 files changed
+7 -1

No files matched your search

+2 -1
View File
@@ -6,6 +6,7 @@ flow dicts so the rest of the pipeline (extract, hosts, endpoints, codegen)
works unchanged, with no mitmproxy or iPhone setup at all.
"""
import base64
import binascii
import json
from urllib.parse import urlencode, urlparse
@@ -108,6 +109,6 @@ def _content_bytes(content):
if content.get("encoding") == "base64":
try:
return base64.b64decode(text)
except ValueError:
except (binascii.Error, ValueError):
return text.encode("utf-8")
return text.encode("utf-8")
+5
View File
@@ -80,3 +80,8 @@ def test_base64_response_body():
assert '"ok"' in msg["response_body"] # base64 "eyJvayI6IHRydWV9" -> {"ok": true}
assert "true" in msg["response_body"]
assert '"to"' in msg["request_body"] # postData decoded too
def test_invalid_base64_response_body_falls_back_to_text():
content = {"text": "not valid base64!", "encoding": "base64"}
assert har._content_bytes(content) == b"not valid base64!"