oxipng icon indicating copy to clipboard operation
oxipng copied to clipboard

Wildcard (*) fails if folder name contains square brackets ([ ])

Open MarcG2 opened this issue 1 year ago • 6 comments

I'm using the Windows 64bit version.

I get a failed to open file for reading error if using this command. "F:\oxipng-9.1.1-x86_64-pc-windows-msvc\oxipng.exe" --dir "F:\Bug test Out" --strip safe -o 2 --verbose "F:\[a]bug test\*.png"

If I ensure the folder name doesn't contain square brackets, the command works as expected. "F:\oxipng-9.1.1-x86_64-pc-windows-msvc\oxipng.exe" --dir "F:\Bug test Out" --strip safe -o 2 --verbose "F:\bug test\*.png"

MarcG2 avatar May 03 '24 22:05 MarcG2

Hi @MarcG2 Square brackets are special syntax within the glob pattern matching so they need to be escaped. You would do this by enclosing each special character with more square brackets: "F:\[[]a[]]bug test\*.png" This looks confusing but it should work 😄 See here for details about glob pattern syntax: https://docs.rs/glob/latest/glob/struct.Pattern.html

andrews05 avatar May 03 '24 23:05 andrews05

@MarcG2 Perhaps worth filing @ https://github.com/rust-lang/glob/issues similar to https://github.com/rust-lang/glob/issues/142 &/or https://github.com/rust-lang/glob/issues/132 ?

TPS avatar May 04 '24 11:05 TPS

Hi @MarcG2 Square brackets are special syntax within the glob pattern matching so they need to be escaped. You would do this by enclosing each special character with more square brackets: "F:\[[]a[]]bug test\*.png" This looks confusing but it should work 😄 See here for details about glob pattern syntax: https://docs.rs/glob/latest/glob/struct.Pattern.html

That explains it. This is second time I've encountered a utility with the same issue. So I'm guessing it's a similar situation with the other one.

@shssoichiro I think it would be a good idea to reference how Oxipng employs this style of pattern matching in the usage section. Most Windows users won't be familiar with it. The asterisk and question mark characters aren't an issue because they're invalid in file names.

Alternatively, you could have Oxipng return a descriptive warning if pattern matching fails when brackets are used.

MarcG2 avatar May 04 '24 15:05 MarcG2

@MarcG2 Perhaps worth filing @ https://github.com/rust-lang/glob/issues similar to rust-lang/glob#142 &/or rust-lang/glob#132 ?

Honestly I wouldn't know what to ask for. Does the library need additional options? Or is this something that should be handled by the end application?

MarcG2 avatar May 04 '24 16:05 MarcG2

@MarcG2 Similar to how you reported this issue & like the linked issues, if you post at the glob repo, that should be enough. The maintainers there will eventually determine the next steps. Linking this issue will help.

TPS avatar May 04 '24 17:05 TPS

We probably just shouldn't have the square bracket pattern syntax, since afaik that's not normal/expected on Windows. However, as already noted, the glob library doesn't have options to disable this (nor do alternatives such as globset) and I don't have much hope that it would add them - it doesn't appear to be highly maintained.

Perhaps oxipng could escape square brackets itself before passing the path to glob. But we would have to be very sure that disallowing character set matching is the appropriate thing to do. Some research on behaviour of other programs might be helpful. See also previous discussions on Windows globbing: https://github.com/shssoichiro/oxipng/pull/536

andrews05 avatar May 04 '24 20:05 andrews05