Independent Auditing of AI Agents. Run by human or the agent itself, to answer the most crucial question in the AI Agent Economy. Is the agent doing what is supposed to do? With iFixAi you can have this answer in less than 120 seconds.
Python agent-evaluationaiai-alignmentai-evaluationai-governanceai-safetyclidiagnostic-tooleu-ai-acthallucination-detectioniso-42001llm-evaluationllm-securitynist-ai-rmfowasp-llmprompt-injectionpythonresponsible-airisk-assessmentrisk-management
fix: accept UTF-8 BOM in dotenv files (#321)
べろしてぃ8dfe0a9721e3
diff --git a/ifixai/cli/init.py b/ifixai/cli/init.pyindex 6ef720a..f5a1c44 100644--- a/ifixai/cli/init.py+++ b/ifixai/cli/init.py@@ -83,7 +83,7 @@ def load_dotenv_file(path: "Path | None" = None) -> list[str]:if not env_path.is_file():return []try:- text = env_path.read_text(encoding="utf-8")+ text = env_path.read_text(encoding="utf-8-sig")except OSError:return []loaded: list[str] = []diff --git a/ifixai/tests/test_dotenv_bom.py b/ifixai/tests/test_dotenv_bom.pynew file mode 100644index 0000000..aea669d--- /dev/null+++ b/ifixai/tests/test_dotenv_bom.py@@ -0,0 +1,31 @@+"""UTF-8 BOMs written by editors must not become part of environment keys."""++import os++import pytest++from ifixai.cli.init import load_dotenv_file++[email protected]("encoding", ["utf-8", "utf-8-sig"])[email protected]("prefix", ["", "export "])+def test_dotenv_first_assignment_accepts_optional_bom(tmp_path, monkeypatch, encoding, prefix):+ key = "IFIXAI_TEST_DOTENV_BOM"+ monkeypatch.setattr(os, "environ", {})+ path = tmp_path / ".env"+ path.write_text(f'{prefix}{key}="fixture-value" # comment\n', encoding=encoding)++ assert load_dotenv_file(path) == [key]+ assert os.environ[key] == "fixture-value"+ assert "\ufeff" + key not in os.environ+++def test_dotenv_bom_preserves_existing_environment(tmp_path, monkeypatch):+ key = "IFIXAI_TEST_DOTENV_BOM"+ monkeypatch.setattr(os, "environ", {key: "shell-value"})+ path = tmp_path / ".env"+ path.write_text(f"{key}=file-value\n", encoding="utf-8-sig")++ assert load_dotenv_file(path) == []+ assert os.environ[key] == "shell-value"+ assert "\ufeff" + key not in os.environ