Skip to content

Commit 0a3feae

Browse files
committed
fix(helpers/path_filter): add space character to the regex mask
WHAT: Add the space character to the path filter regex mask. This change allows the include/exclude filters to correctly handle file names that contain spaces. WHY: This fixes a bug reported by a user: #2594 Closes #2594
1 parent 8a67cda commit 0a3feae

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

strictdoc/helpers/path_filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
from typing import List
33

4-
REGEX_NAME_PART = r"[A-Za-z0-9-_\.]+"
4+
REGEX_NAME_PART = r"[A-Za-z0-9-_\. ]+"
55
REGEX_FILENAME = rf"{REGEX_NAME_PART}"
66
REGEX_FOLDER = rf"{REGEX_NAME_PART}"
77

tests/unit/strictdoc/core/test_file_tree.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,46 @@ def test_53_both_include_and_exclude_paths():
135135
found_file2 = folder.files[1]
136136
assert isinstance(found_file2, File)
137137
assert found_file2.full_path == path_to_file2
138+
139+
140+
def test_54_exclude_paths():
141+
"""
142+
Verify that spaces in filenames have no effect on the exclusion/inclusion
143+
of files.
144+
145+
This test ensures a proper fix for the issue reported in:
146+
https://github.com/strictdoc-project/strictdoc/issues/2594
147+
"""
148+
149+
with tempfile.TemporaryDirectory() as tmp_dir:
150+
path_to_file1 = os.path.join(tmp_dir, "file1.py")
151+
path_to_file2 = os.path.join(tmp_dir, "file2.py")
152+
path_to_file3 = os.path.join(tmp_dir, "dev/file 3.log")
153+
154+
Path(path_to_file3).parent.mkdir(parents=True, exist_ok=True)
155+
156+
Path(path_to_file1).touch()
157+
Path(path_to_file2).touch()
158+
Path(path_to_file3).touch()
159+
160+
file_tree = FileFinder.find_files_with_extensions(
161+
root_path=tmp_dir,
162+
ignored_dirs=[],
163+
extensions=[".py", ".log"],
164+
include_paths=[],
165+
exclude_paths=["**/*.log"],
166+
)
167+
168+
assert isinstance(file_tree, FileTree)
169+
assert isinstance(file_tree.root_folder_or_file, Folder)
170+
171+
folder: Folder = file_tree.root_folder_or_file
172+
assert folder.full_path == tmp_dir
173+
assert len(folder.files) == 2
174+
175+
# Verify that the .log file is not found.
176+
assert len(folder.subfolder_trees) == 1, folder.subfolder_trees
177+
subfolder = folder.subfolder_trees[0]
178+
assert subfolder.full_path == os.path.join(tmp_dir, "dev")
179+
assert len(subfolder.files) == 0
180+
assert len(subfolder.subfolder_trees) == 0

0 commit comments

Comments
 (0)