Skip to content

paths.is_hidden() Reports invalid input as hidden #423

Open
@matyanwek

Description

@matyanwek

A bug in a previous version of Jupyter led to errors when trying to rename a file.
After a bit of digging, I think I've tracked down the root cause to
line 497 of jupyter_core/paths.py,
where the assignment inside_root = abs_path[len(abs_root) :] assumes that the abs_path will have abs_root as a prefix.
In some cases, the abs_path could get trimmed down to exactly the file extension,
like in this case:

is_hidden("filename.ipynb", "/home/aa")

where filename is exactly the same length as /home/aa.
The resulting trimmed file extension .ipynb looks like a hidden file when checked.

A simple way to fix this would be to check that abs_root is a prefix of abs_path before trimming:

if abs_path.startswith(abs_root):
    inside_root = abs_path[len(abs_root):]
else:
    inside_root = abs_path

I'd also propose to fix the check on abs_root on line 495,
since the call to os.path.normpath() on line 487 ensures it will never be an empty string:

    abs_path = os.path.normpath(abs_path)
    if abs_root == "":
        abs_root = abs_path.split(os.sep, 1)[0] + os.sep
    else:
        abs_root = os.path.normpath(abs_root)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions