Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix globbing of filenames that contain special glob characters #1405

Merged
merged 2 commits into from Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion coverage/data.py
Expand Up @@ -70,7 +70,7 @@ def combinable_files(data_file, data_paths=None):
if os.path.isfile(p):
files_to_combine.append(os.path.abspath(p))
elif os.path.isdir(p):
pattern = os.path.join(os.path.abspath(p), f"{local}.*")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The p here should also be escaped, there is no guarantee that it won't have [ or ] in it

pattern = glob.escape(os.path.join(os.path.abspath(p), local)) +".*"
files_to_combine.extend(glob.glob(pattern))
else:
raise NoDataError(f"Couldn't combine from non-existent path '{p}'")
Expand Down
4 changes: 2 additions & 2 deletions coverage/sqldata.py
Expand Up @@ -774,8 +774,8 @@ def erase(self, parallel=False):
file_be_gone(self._filename)
if parallel:
data_dir, local = os.path.split(self._filename)
localdot = local + ".*"
pattern = os.path.join(os.path.abspath(data_dir), localdot)
local_abs_path = os.path.join(os.path.abspath(data_dir), local)
pattern = glob.escape(local_abs_path) + ".*"
for filename in glob.glob(pattern):
if self._debug.should("dataio"):
self._debug.write(f"Erasing parallel data file {filename!r}")
Expand Down