Skip to content

Commit 0b7f49a

Browse files
authored
Fixed globbing for files that were unintentionally filtering out path… (#143)
* Fixed globbing for files that were unintentionally filtering out paths that started with a dot * Removed unused imports
1 parent 9fd102a commit 0b7f49a

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.2.57"
9+
version = "2.2.59"
1010
requires-python = ">= 3.10"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.2.57'
2+
__version__ = '2.2.59'
33
USER_AGENT = f'SocketPythonCLI/{__version__}'

socketsecurity/core/__init__.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44
import tarfile
55
import tempfile
66
import time
7-
import io
87
import json
98
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
1411

1512
if TYPE_CHECKING:
1613
from socketsecurity.config import CliConfig
@@ -315,15 +312,18 @@ def find_files(self, path: str, ecosystems: Optional[List[str]] = None) -> List[
315312

316313
for pattern in expanded_patterns:
317314
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}")
321317
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)
323322

324323
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("\\", "/"))
327327

328328
glob_end = time.time()
329329
log.debug(f"Globbing took {glob_end - glob_start:.4f} seconds")
@@ -414,6 +414,11 @@ def has_manifest_files(self, files: list) -> bool:
414414
# Expand brace patterns for each manifest pattern
415415
expanded_patterns = Core.expand_brace_pattern(pattern_str)
416416
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+
417422
for file in norm_files:
418423
# Use PurePath.match for glob-like matching
419424
if PurePath(file).match(exp_pat):

0 commit comments

Comments
 (0)