|
4 | 4 | import tarfile |
5 | 5 | import tempfile |
6 | 6 | import time |
7 | | -import io |
8 | 7 | import json |
9 | 8 | from dataclasses import asdict |
10 | | -from glob import glob |
11 | | -from io import BytesIO |
12 | | -from pathlib import PurePath |
13 | | -from typing import BinaryIO, Dict, List, Tuple, Set, Union, TYPE_CHECKING, Optional |
| 9 | +from pathlib import Path, PurePath |
| 10 | +from typing import Dict, List, Tuple, Set, TYPE_CHECKING, Optional |
14 | 11 |
|
15 | 12 | if TYPE_CHECKING: |
16 | 13 | from socketsecurity.config import CliConfig |
@@ -315,15 +312,18 @@ def find_files(self, path: str, ecosystems: Optional[List[str]] = None) -> List[ |
315 | 312 |
|
316 | 313 | for pattern in expanded_patterns: |
317 | 314 | case_insensitive_pattern = Core.to_case_insensitive_regex(pattern) |
318 | | - file_path = os.path.join(path, "**", case_insensitive_pattern) |
319 | | - |
320 | | - log.debug(f"Globbing {file_path}") |
| 315 | + |
| 316 | + log.debug(f"Searching for pattern: {case_insensitive_pattern}") |
321 | 317 | glob_start = time.time() |
322 | | - glob_files = glob(file_path, recursive=True) |
| 318 | + |
| 319 | + # Use pathlib.Path.rglob() instead of glob.glob() to properly match dotfiles/dotdirs |
| 320 | + base_path = Path(path) |
| 321 | + glob_files = base_path.rglob(case_insensitive_pattern) |
323 | 322 |
|
324 | 323 | for glob_file in glob_files: |
325 | | - if os.path.isfile(glob_file) and not Core.is_excluded(glob_file, self.config.excluded_dirs): |
326 | | - files.add(glob_file.replace("\\", "/")) |
| 324 | + glob_file_str = str(glob_file) |
| 325 | + if os.path.isfile(glob_file_str) and not Core.is_excluded(glob_file_str, self.config.excluded_dirs): |
| 326 | + files.add(glob_file_str.replace("\\", "/")) |
327 | 327 |
|
328 | 328 | glob_end = time.time() |
329 | 329 | log.debug(f"Globbing took {glob_end - glob_start:.4f} seconds") |
@@ -414,6 +414,11 @@ def has_manifest_files(self, files: list) -> bool: |
414 | 414 | # Expand brace patterns for each manifest pattern |
415 | 415 | expanded_patterns = Core.expand_brace_pattern(pattern_str) |
416 | 416 | for exp_pat in expanded_patterns: |
| 417 | + # If pattern doesn't contain '/', prepend '**/' to match files in any subdirectory |
| 418 | + # This ensures patterns like '*requirements.txt' match '.test/requirements.txt' |
| 419 | + if '/' not in exp_pat: |
| 420 | + exp_pat = f"**/{exp_pat}" |
| 421 | + |
417 | 422 | for file in norm_files: |
418 | 423 | # Use PurePath.match for glob-like matching |
419 | 424 | if PurePath(file).match(exp_pat): |
|
0 commit comments