Skip to content

Commit 227b4f5

Browse files
marcelsafinCopilot
andauthored
fix: normalize non-UTF-8 integration manifests (#3862)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6751435 commit 227b4f5

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎src/specify_cli/integrations/manifest.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,10 @@ def load(
471471
path = inst.manifest_path
472472
try:
473473
data = json.loads(path.read_text(encoding="utf-8"))
474+
except UnicodeDecodeError as exc:
475+
raise ValueError(
476+
f"Integration manifest at {path} is not valid UTF-8"
477+
) from exc
474478
except json.JSONDecodeError as exc:
475479
raise ValueError(
476480
f"Integration manifest at {path} contains invalid JSON"

‎tests/integrations/test_manifest.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,14 @@ def test_load_invalid_json_raises(self, tmp_path):
375375
with pytest.raises(ValueError, match="invalid JSON"):
376376
IntegrationManifest.load("bad", tmp_path)
377377

378+
def test_load_non_utf8_json_raises_value_error(self, tmp_path):
379+
path = tmp_path / ".specify" / "integrations" / "bad.manifest.json"
380+
path.parent.mkdir(parents=True)
381+
path.write_bytes(b"\xff\xfe")
382+
383+
with pytest.raises(ValueError, match="valid UTF-8"):
384+
IntegrationManifest.load("bad", tmp_path)
385+
378386
def test_load_filters_recovered_files_not_in_files(self, tmp_path):
379387
# Finding B (Round-9): a recovered_files entry referencing a path
380388
# not present in files indicates an internally-inconsistent manifest

0 commit comments

Comments
 (0)