fix(plugins): read the first-party list as UTF-8 on every system

The list was read in the system's code page. Its about texts hold curly
apostrophes, so the packaged app on Windows showed "site’s" in Western code
pages and could not read the list at all on cp932 or cp936 systems: the
Plugins screen, connecting SurfSense's plugins and adding a custom one all
failed. The test writes the apostrophe as raw UTF-8 and fails on a cp1252
Windows machine without the fix.
This commit is contained in:
DESKTOP-RTLN3BA\$punk 2026-10-13 22:34:28 -07:00
parent 4ad33c4c1e
commit 298a778889
2 changed files with 19 additions and 1 deletions

View file

@ -21,7 +21,9 @@ def icons_beside(path: Path) -> Path:
def checked_entries(path: Path) -> list[ListEntry]:
"""Every entry, or a ValueError naming the entry and the field that is wrong."""
entries: list[ListEntry] = []
for raw in json.loads(path.read_text())["plugins"]:
# UTF-8 whatever the system's code page: Windows would read the list's curly
# apostrophes as cp1252, and fail on a cp932 or cp936 system.
for raw in json.loads(path.read_text(encoding="utf-8"))["plugins"]:
name = raw.get("id", "?")
try:
entry = ListEntry.model_validate(raw)

View file

@ -38,6 +38,22 @@ def listed(tmp_path: Path, *entries: dict[str, Any]) -> Path:
return path
def test_the_list_is_read_as_utf_8_whatever_the_system_code_page(
tmp_path: Path,
) -> None:
"""The shipped list holds curly apostrophes, and Windows reads in its code page unless told."""
about = "Read a site\u2019s pages as clean text."
path = tmp_path / "plugins.json"
path.write_bytes(
json.dumps(
{"schema_version": 1, "plugins": [scrapers(about=about)]},
ensure_ascii=False,
).encode("utf-8")
)
assert checked_entries(path)[0].about == about
def test_the_packaged_list_passes_its_check() -> None:
"""A bad entry fails CI here, not on a user's machine.