Issue6665
Created on 2009-08-07 09:49 by rajcze, last changed 2009-11-01 20:37 by gregory.p.smith.
|
msg91398 - (view) |
Author: Josef Skladanka (rajcze) |
Date: 2009-08-07 09:49 |
|
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.
|
|
msg91638 - (view) |
Author: Gregory P. Smith (gregory.p.smith) |
Date: 2009-08-16 18:31 |
|
haha wow I just read the fnmatch code... trunk r2734 | guido | 1992-01-12
added fnmatch._cache for it to cache compiled regular expressions. That
has -long- since become unnecessary as the re module does that itself. ;)
I'll clean this up while fixing this bug.
|
|
msg91639 - (view) |
Author: Gregory P. Smith (gregory.p.smith) |
Date: 2009-08-16 18:33 |
|
aww, i guess the _cache does cache the result of the glob -> regular
expression translation. it needs to stay for that.
|
|
msg91640 - (view) |
Author: Gregory P. Smith (gregory.p.smith) |
Date: 2009-08-16 18:48 |
|
changing the '$' to \Z(?ms)' fixes the problem.
|
|
msg91642 - (view) |
Author: Gregory P. Smith (gregory.p.smith) |
Date: 2009-08-16 18:58 |
|
fixed in trunk r74475, py3k r74476
|
|
msg91643 - (view) |
Author: Gregory P. Smith (gregory.p.smith) |
Date: 2009-08-16 19:00 |
|
I'll backport this to 2.6 and 3.1 later (its too late for 3.1.1).
|
|
msg94804 - (view) |
Author: Gregory P. Smith (gregory.p.smith) |
Date: 2009-11-01 20:37 |
|
release26-maint r76023 to appear in Python 2.6.5.
release31-maint r76024 to appear in Python 3.1.2.
|
|
| Date |
User |
Action |
Args |
| 2009-11-01 20:37:14 | gregory.p.smith | set | status: open -> closed resolution: fixed messages:
+ msg94804
|
| 2009-08-16 19:00:52 | gregory.p.smith | set | messages:
+ msg91643 versions:
- Python 2.7, Python 3.2 |
| 2009-08-16 18:59:00 | gregory.p.smith | set | messages:
+ msg91642 |
| 2009-08-16 18:48:32 | gregory.p.smith | set | messages:
+ msg91640 |
| 2009-08-16 18:33:59 | gregory.p.smith | set | messages:
+ msg91639 |
| 2009-08-16 18:31:36 | gregory.p.smith | set | priority: normal
messages:
+ msg91638 |
| 2009-08-16 18:12:16 | gregory.p.smith | set | assignee: gregory.p.smith
nosy:
+ gregory.p.smith |
| 2009-08-07 09:49:17 | rajcze | create | |
|