-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
fnmatch should use re.search() #32123
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
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). CLA MissingOur records indicate the following people have not signed the CLA: For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
Every change to Python requires a NEWS entry. Please, add it using the blurb_it Web app or the blurb command-line tool. |
Github is not set up. Only after "Update - Rebase" did the bot call the reviewer. For other projects, this button is not available to me. |
Hi, I'm not a bot :) I'm a very human triager. |
But @cpython-cla-bot - bot 😄 |
That's just because they're the new bot on the block! They didn't exist when you first filed the PR (and nor did Bedevere's "please add a NEWS entry" functionality), but now they do, so adding new commits to your branch triggered them. |
The current behavior is correct: >>> fnmatch.fnmatch('/bin/busybox', 'busybox')
False
>>> fnmatch.fnmatch('busybox', 'busybox')
True
>>> fnmatch.fnmatch('/bin/busybox', '*busybox') # note the *
True The problem is not with the end of the string, but with the beginning:
|
Concur with @ezio-melotti. |
#include <stdio.h>
#include <fnmatch.h>
int main() {
printf("%d=False %d=True %d=True\n",
fnmatch("/bin/busybox", "busybox", 0),
fnmatch("busybox", "busybox", 0),
fnmatch("/bin/busybox", "*busybox", 0)
);
}
// 1=False 0=True 1=True https://man7.org/linux/man-pages/man3/fnmatch.3.html and GCC re.search: fnmatch.fnmatch('/bin/busybox', 'busybox')
Out[2]: True
fnmatch.fnmatch('busybox', 'busybox')
Out[3]: True
fnmatch.fnmatch('/bin/busybox', '*busybox')
Out[4]: True My version meets the standard for option 1. |
You are confused by the fact that the C's fnmatch and the Python's fnmatch have different order of parameters. |
#include <stdio.h>
#include <fnmatch.h>
int main()
{
printf("1st=%d 2nd=%d 3rd=%d\n",
fnmatch("busybox", "/bin/busybox", 0),
fnmatch("busybox", "busybox", 0),
fnmatch("*busybox", "/bin/busybox", 0)
);
return 0;
} Outputs
This means that the first example didn't match, whereas the other two did, so it's consistent with Python's behavior and the example I posted above. |
But
It was this pattern that made me create the patch. |
Please read more carefully what @ezio-melotti has written above. |
re.match
does not work with the end of a string (\Z
or$
).