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

BUG: Wildcard (*) fails if folder name contains square brackets ([ ]) #618

Open
MarcG2 opened this issue May 3, 2024 · 6 comments
Open

Comments

@MarcG2
Copy link

MarcG2 commented May 3, 2024

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"

@andrews05
Copy link
Collaborator

andrews05 commented May 3, 2024

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

@TPS
Copy link

TPS commented May 4, 2024

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

@MarcG2
Copy link
Author

MarcG2 commented May 4, 2024

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
Copy link
Author

MarcG2 commented May 4, 2024

@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?

@TPS
Copy link

TPS commented May 4, 2024

@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.

@andrews05
Copy link
Collaborator

andrews05 commented May 4, 2024

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: #536

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants