fix: restore utf-8-sig BOM tolerance at .env readers the sweep normalized
The cherry-pick auto-resolution + AST sweep applied plain utf-8 at three .env reader sites where the salvaged PRs (#62617, #62123) deliberately use utf-8-sig — a Notepad BOM must not hide/duplicate the first key. Restore the contract (tests pin it).
This commit is contained in:
parent
75e0d52034
commit
0a6fda01e3
@ -13357,7 +13357,11 @@ def _render_distribution_plan(plan) -> None:
|
||||
env_path = plan.target_dir / ".env"
|
||||
if env_path.is_file():
|
||||
try:
|
||||
for raw in env_path.read_text(encoding="utf-8").splitlines():
|
||||
# .env is written as UTF-8 everywhere in the codebase,
|
||||
# but a Notepad-edited file can carry a BOM — read as
|
||||
# utf-8-sig so the first key isn't hidden behind
|
||||
# U+FEFF (#62617).
|
||||
for raw in env_path.read_text(encoding="utf-8-sig").splitlines():
|
||||
line = raw.strip()
|
||||
if not line or line.startswith("#"):
|
||||
continue
|
||||
|
||||
@ -897,7 +897,8 @@ class HindsightMemoryProvider(MemoryProvider):
|
||||
env_path = Path(hermes_home) / ".env"
|
||||
existing_llm_key = ""
|
||||
if env_path.exists():
|
||||
for line in env_path.read_text(encoding="utf-8").splitlines():
|
||||
# utf-8-sig: a Notepad BOM must not hide the first key.
|
||||
for line in env_path.read_text(encoding="utf-8-sig").splitlines():
|
||||
if line.startswith("HINDSIGHT_LLM_API_KEY="):
|
||||
existing_llm_key = line.split("=", 1)[1]
|
||||
break
|
||||
@ -927,7 +928,10 @@ class HindsightMemoryProvider(MemoryProvider):
|
||||
env_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
existing_lines = []
|
||||
if env_path.exists():
|
||||
existing_lines = env_path.read_text(encoding="utf-8").splitlines()
|
||||
# utf-8-sig: a Notepad BOM would glue U+FEFF onto the first
|
||||
# key, defeating the in-place update below and appending a
|
||||
# duplicate line instead.
|
||||
existing_lines = env_path.read_text(encoding="utf-8-sig").splitlines()
|
||||
updated_keys = set()
|
||||
new_lines = []
|
||||
for line in existing_lines:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user