From 756bb2d77538d052ef14cecbf59917672629187a Mon Sep 17 00:00:00 2001 From: Ghraven <115199279+Ghraven@users.noreply.github.com> Date: Wed, 20 May 2026 18:54:42 +0000 Subject: [PATCH] fix: add explicit encoding="utf-8" to text-mode file I/O Several text-mode open() calls relied on the platform default encoding (cp1252 on Windows) when reading/writing JSON test-case files, the JSONL streamlit log, and the bundled index.html. JSON and JSONL are UTF-8 per RFC 8259, so non-ASCII content could raise UnicodeDecodeError or be corrupted on non-UTF-8 platforms. Pinning encoding="utf-8" makes behavior consistent everywhere. --- burr/cli/__main__.py | 4 ++-- burr/integrations/streamlit.py | 2 +- burr/testing/__init__.py | 2 +- burr/tracking/server/run.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/burr/cli/__main__.py b/burr/cli/__main__.py index 5bbc99dd5..8967602d9 100644 --- a/burr/cli/__main__.py +++ b/burr/cli/__main__.py @@ -477,14 +477,14 @@ def create_test_case( if target_file_name: # if it already exists, load it up and append to it if os.path.exists(target_file_name): - with open(target_file_name, "r") as f: + with open(target_file_name, "r", encoding="utf-8") as f: # assumes it's a list of test cases current_testcases = json.load(f) current_testcases.append(tc_json) else: current_testcases = [tc_json] print(f"\nWriting data to file {target_file_name}") - with open(target_file_name, "w") as f: + with open(target_file_name, "w", encoding="utf-8") as f: json.dump(current_testcases, f, indent=2) else: logger.info(json.dumps(tc_json, indent=2)) diff --git a/burr/integrations/streamlit.py b/burr/integrations/streamlit.py index 71b63bce0..c3b1df159 100644 --- a/burr/integrations/streamlit.py +++ b/burr/integrations/streamlit.py @@ -95,7 +95,7 @@ def load_state_from_log_file(jsonl_log_file: str, app: Application) -> AppState: :return: AppState """ out = [] - for i, line in enumerate(open(jsonl_log_file)): + for i, line in enumerate(open(jsonl_log_file, encoding="utf-8")): json_line = json.loads(line) record = Record( state=json_line["state"], diff --git a/burr/testing/__init__.py b/burr/testing/__init__.py index f1caa19bf..bd89af77f 100644 --- a/burr/testing/__init__.py +++ b/burr/testing/__init__.py @@ -26,7 +26,7 @@ # and then load it for the test. def load_test_cases(file_name: str) -> tuple: """Load test cases from a json file.""" - with open(file_name, "r") as f: + with open(file_name, "r", encoding="utf-8") as f: json_test_cases = json.load(f) test_cases = [(tc.get("input_state"), tc.get("expected_state")) for tc in json_test_cases] test_ids = [ diff --git a/burr/tracking/server/run.py b/burr/tracking/server/run.py index ad253cc6b..4c6b941f3 100644 --- a/burr/tracking/server/run.py +++ b/burr/tracking/server/run.py @@ -375,7 +375,7 @@ async def version() -> dict: ui_app.mount("/public", StaticFiles(directory=base_asset_directory, html=True), "/public") # Read index.html once at startup - with open(os.path.join(base_asset_directory, "index.html")) as f: + with open(os.path.join(base_asset_directory, "index.html"), encoding="utf-8") as f: _index_html_template = f.read() @ui_app.get("/manifest.json")