Skip to content

💫 Toolkit to help you get started with SDD or any other process!

fix: report a non-file .extensionignore or .presetignore as a validation error (#5131)

John Costa3b76e6ea2dbe
diff --git a/src/specify_cli/_install_ignore.py b/src/specify_cli/_install_ignore.py
index 68c3bcbcb..b3e69881b 100644
--- a/src/specify_cli/_install_ignore.py
+++ b/src/specify_cli/_install_ignore.py
@@ -17,14 +17,16 @@ def load_install_ignore(
Match the extension installer's Git-style patterns, including whitespace
trimming and backslash normalization. Only the named root ignore file is
read; there are no default exclusions except the ignore filename itself.
- Invalid encoding or patterns raise the caller's domain validation error
- before copying.
+ A non-file path, invalid encoding, or invalid patterns raise the caller's
+ domain validation error before copying.
Excluded directories are pruned by copytree, so child negations cannot
restore files inside them unless the parent directory is also re-included.
"""
ignore_file = source_dir / ignore_filename
if not ignore_file.exists():
return None
+ if not ignore_file.is_file():
+ raise validation_error(f"{ignore_filename} is not a regular file: {ignore_file}")
# Accept UTF-8 with or without the BOM emitted by Windows PowerShell 5.1.
# Strip it after decoding so error offsets remain relative to the file.
diff --git a/tests/specify_cli/test_install_ignore.py b/tests/specify_cli/test_install_ignore.py
index 82a68b742..8b6e9c5ee 100644
--- a/tests/specify_cli/test_install_ignore.py
+++ b/tests/specify_cli/test_install_ignore.py
@@ -192,3 +192,14 @@ def test_read_failure_is_propagated(tmp_path, ignore_contract, monkeypatch):
monkeypatch.setattr(Path, "read_text", fail_read)
with pytest.raises(PermissionError, match="ignore file is unreadable"):
load_install_ignore(tmp_path, ignore_filename, validation_error)
+
+
+def test_directory_named_like_ignore_file_uses_callers_validation_error(tmp_path, ignore_contract):
+ ignore_filename, validation_error = ignore_contract
+ ignore_dir = tmp_path / ignore_filename
+ ignore_dir.mkdir()
+
+ with pytest.raises(validation_error) as caught:
+ load_install_ignore(tmp_path, ignore_filename, validation_error)
+
+ assert f"{ignore_filename} is not a regular file: {ignore_dir}" in str(caught.value)