karlch / vimiv-qt

An image viewer with vim-like keybindings
https://karlch.github.io/vimiv-qt/
GNU General Public License v3.0
179 stars 14 forks source link

Bug: mark does not work if path contains "[" and "]" #553

Open pglira opened 1 year ago

pglira commented 1 year ago

It seems that an image can not be marked (with the mark command or by pressing m) if the path contains both, an opening and a closing square bracket.

Some examples where marking an image doesn't work ...

/tmp/[a]/image.png
/tmp/[aa]/image.png

and where it works as usual

/tmp/a]/image.png
/tmp/[a/image.png
/tmp/[]/image.png

I've also tested the same paths with round and curly brackets. I observed no issues in these cases.

I can try to fix the issue and submit a PR if somebody can give me a hint where to start.

karlch commented 1 year ago

Thank you for your detailed bug report! I can reproduce the issue, and it seems to be related to pythons globbing module which interprets the content in square brackets.

In vimiv.api.commands the path expansion is done in the lines 260 following, here with two debug print statements added:

    @classmethod
    def paths_type(cls, globstr: str) -> typing.List[str]:
        """Retrieve list of paths matching the globstr passed."""
        print(escape_glob(globstr))
        paths = glob.glob(os.path.expanduser(escape_glob(globstr)), recursive=True)
        print(paths)
        if not paths:
            raise ArgumentError(f"No paths matching '{globstr}'")
        return paths

and clearly the brackets are not escaped properly. While we could just use glob.escape here instead (and this fixes the issue), the function in vimiv.utils called (escape_glob) should be fixed in any case (i.e. regex fixed) as we need the different escaping for external commands currently.

Would you like to take a look into this?

pglira commented 1 year ago

Yes, of course, with this I can try to fix it. Thanks.

TeaWhyDee commented 1 year ago

Another case: Filenames with symbols '*', '\~', '?' also break marking, using '%m' also breaks Example: "image.png~"