fix(rcfile): read .graphifyrc with utf-8-sig so a BOM doesn't drop the first key

Windows PowerShell 5.1 (Set-Content -Encoding UTF8) and older Notepad save
UTF-8 with a BOM. load_graphifyrc read the file as plain utf-8, so the BOM
became part of the first key; unknown keys are ignored by design, so that
setting (say language.inc=php) vanished without a warning. Read with
utf-8-sig, as the other Windows-edited files in the repo already are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Rudy CelekliandClaude Opus 5.5 authored and safishamsi committed 2026-10-20 10:35:22 +01:00
1 parent 86c57be820
commit 0d69958ff1
2 files changed
+17 -1

No files matched your search

+4 -1
View File
@@ -123,7 +123,10 @@ def load_graphifyrc(root: Path) -> dict:
cfg: dict = {}
languages: dict[str, str] = {}
content = rc_path.read_text(encoding="utf-8")
# utf-8-sig: Windows PowerShell 5.1 (`Set-Content -Encoding UTF8`) and older
# Notepad save UTF-8 with a BOM. Read as plain utf-8, the BOM became part of
# the first key, which then matched nothing and was ignored without a word.
content = rc_path.read_text(encoding="utf-8-sig")
for line_num, raw in enumerate(content.splitlines(), 1):
line = raw.strip()
if not line or line.startswith("#"):
+13
View File
@@ -91,6 +91,19 @@ def test_language_line_maps_an_extension_to_a_canonical_suffix(tmp_path):
assert load_graphifyrc(tmp_path) == {"languages": {".inc": ".php"}}
def test_a_utf8_bom_does_not_swallow_the_first_key(tmp_path):
"""A .graphifyrc saved with a UTF-8 BOM (Windows PowerShell 5.1, older
Notepad) must not glue the BOM onto its first key, which then matched
nothing and was dropped without a warning."""
(tmp_path / ".graphifyrc").write_bytes(
"\ufefflanguage.inc=php\nviz_node_limit=500\n".encode("utf-8")
)
assert load_graphifyrc(tmp_path) == {
"languages": {".inc": ".php"},
"viz_node_limit": 500,
}
@pytest.mark.parametrize("key", ["language.inc", "language..inc", "language.INC", "language. inc "])
def test_the_extension_key_is_normalised(tmp_path, key):
(tmp_path / ".graphifyrc").write_text(f"{key}=php\n", encoding="utf-8")