This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rajcze
Recipients rajcze
Date 2009-08-07.09:49:14
SpamBayes Score 5.23231e-10
Marked as misclassified No
Message-id <1249638559.7.0.0574356115412.issue6665@psf.upfronthosting.co.za>
In-reply-to
Content
Hello,
at the moment, fnmatch.fnmatch() will fail to match any string, which
has \n character. This of course breaks glob as well.

Example

> import fnmatch
> fnmatch.fnmatch("foo\nbar", "foo*")
False

> import glob
> open("foobar", "w").close()
> open("foo\nbar", "w").close()
> glob.glob("foo*")
['foobar']

while the expected result is ['foobar', 'foo\nbar']. The standard C
fnmatch function from fnmatch.h is behaving correctly i.e. this code
will print out "match!"

#include <fnmatch.h>
#include <stdio.h>

int main()
{
    if (fnmatch("foo*", "foo\nbar", FNM_NOESCAPE) == 0)
        printf("match!\n");
    else
        printf("fail!\n");
    return 0;
}


This misbehaviour is caused by the fnmatch.translate() which adds $ to
the end of the regexp. Without the ending $ the fnmatch function works OK.
History
Date User Action Args
2009-08-07 09:49:20rajczesetrecipients: + rajcze
2009-08-07 09:49:19rajczesetmessageid: <1249638559.7.0.0574356115412.issue6665@psf.upfronthosting.co.za>
2009-08-07 09:49:16rajczelinkissue6665 messages
2009-08-07 09:49:14rajczecreate