[issue6665] fnmatch fails on filenames containing \n character
Josef Skladanka
report at bugs.python.org
Fri Aug 7 11:49:19 CEST 2009
New submission from Josef Skladanka <jskladan at redhat.com>:
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.
----------
components: Library (Lib)
messages: 91398
nosy: rajcze
severity: normal
status: open
title: fnmatch fails on filenames containing \n character
type: behavior
versions: Python 2.4, Python 2.5, Python 2.6, Python 2.7, Python 3.0, Python 3.1, Python 3.2
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6665>
_______________________________________
More information about the Python-bugs-list
mailing list