vimiv-qt icon indicating copy to clipboard operation
vimiv-qt copied to clipboard

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

Open pglira opened this issue 2 years ago • 3 comments

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.

pglira avatar Dec 16 '22 00:12 pglira

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?

karlch avatar Jan 03 '23 10:01 karlch

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

pglira avatar Jan 09 '23 07:01 pglira

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

TeaWhyDee avatar May 27 '23 10:05 TeaWhyDee