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

Not follow symlinks in Ensure basename_wo_ext() #139

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion audeer/core/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def basename_wo_ext(
'file'

"""
path = safe_path(path)
path = safe_path(path, follow_symlink=False) # convert byte to str
path = os.path.basename(path)
if ext is not None:
if not ext.startswith("."):
Expand Down
9 changes: 9 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,15 @@ def test_basename_wo_ext(path, ext, basename):
assert isinstance(b, str)


def test_basename_wo_ext_symlink(tmpdir):
# Ensure basename_wo_ext() is not influenced by existing files
file = audeer.touch(tmpdir, "file.txt")
link = os.path.join(tmpdir, "link.txt")
os.symlink(file, link)
assert audeer.basename_wo_ext(file) == "file"
assert audeer.basename_wo_ext(link) == "link"


@pytest.mark.parametrize(
"dirs,expected",
[
Expand Down