-
Notifications
You must be signed in to change notification settings - Fork 125
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
Added support for glob patterns in quotes #536
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unfortunate that windows neither handles this automatically nor even has a "standard" way of dealing with it, but I think this is a good change as it seems glob is more widely used than wild.
Question: Is it still possible to provide a path containing a literal *
?
Handling |
I believe we need to think more about how to properly fix this. The
Actually, it is possible to name a file
How do built-in Windows commands handle these quotations and glob expansion? Given that Windows is being awkward here as it usually tends to be, I think that's the closest thing to a "source of truth" we have for OxiPNG. |
Here is comparison of different programs (cp, oxipng with wild, oxipng with glob) There is how
this is how
version with
|
Thanks, those results are interesting. However, PowerShell is a bit more sane and feels more "Unix-like" in these aspects: I wouldn't be surprised if it did glob expansion. How does the picture look like with the old |
Works exactly the same as on PowerShell:
|
This is interesting. The results suggest that if native Windows commands don't allow escaping |
You're right, we do need to sure about this and I'll continue trying to research it...
I think this issue concerns using glob on other systems where globbing is already performed. Given @SalOne22 has restricted usage here to Windows only, I think the behaviour is correct (as in, as normal/expected as anything else on Windows). |
src/main.rs
Outdated
@@ -295,7 +295,7 @@ Heuristic filter selection strategies: | |||
8 => BigEnt Highest Shannon entropy of bigrams | |||
9 => Brute Smallest compressed size (slow)", | |||
) | |||
.get_matches_from(wild::args()); | |||
.get_matches(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll just note that there's a subtle difference to be aware of here: wild::args()
corresponds to env::args()
, while get_matches()
uses env::args_os()
(corresponding to wild::args_os()
). It affects what happens with paths that contain invalid UTF-8.
Not suggesting to change anything, just pointing this out.
Everything I can find suggests that while it is technically possible for paths containing That said, I've just realised the glob function can return nothing if there were no matches, even if no wildcard was used. So if you do fn apply_glob_pattern(path: PathBuf) -> Vec<PathBuf> {
let matches = path
.to_str()
.and_then(|pattern| glob::glob(pattern).ok())
.map(|paths| paths.flatten().collect::<Vec<_>>());
match matches {
Some(paths) if !paths.is_empty() => paths,
_ => vec![path],
}
} Possibly related: #170 (comment). We should make sure this is all working as expected too. |
That is a reasonable choice, in my opinion. However, in Unix-like shells, it is possible to pass |
Here is some tests from windows PowerShell:
This is tests from cmd:
|
Can you try |
(no output)
(no output) |
Sorry for the question, but what is the |
That's a good question! I think that flag can be useful for very dense directory hierarchies, where shell glob expansion would cause a too long command line parameter string. |
So if the way I see things is correct, we should choose from two approaches here:
What do you think it's the right tradeoff here? I'd lean towards the correctness and logical predictability of keeping glob expansion behavior consistent between platforms, but UX is also an important concern. |
About escaping
|
On a Mac, consistent UX within the platform is more important to me than consistent UX across platforms. I'm bothered by applications that use non-native UIs or follow Windows conventions. A good cross-platform application is one that adapts to each platform to "fit in" appropriately. Given we are currently breaking people's expectations and making it harder for them to use oxipng, I'm in favour of switching to |
Alright, at the moment I'm convinced that expanding globs between quotations is the better way to go on Windows. People with advanced needs will bend over backwards with unusual filenames anyway. Let's see if Kornel or Josh have something to add to the discussion. |
@SalOne22 Could you update from master and fix merge conflicts? |
Added support for glob patterns in windows paths with spaces that surrounded with quotes closes shssoichiro#373
Added support for glob patterns in windows paths with spaces that surrounded with quotes
This pull request can be closed if you decided to not change the input files behavior. Because this can be less robust than
wild
crate. Inwild
special characters in quotes ("*") are intentionally not expanded.closes #373