[Python-bugs-list] [ python-Bugs-409651 ] fnmatch doesn't escape '\' between [...]

noreply@sourceforge.net noreply@sourceforge.net
Mon, 19 Mar 2001 15:35:28 -0800


Bugs item #409651, was updated on 2001-03-18 21:07
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=409651&group_id=5470

Category: Python Library
Group: None
Status: Open
Priority: 5
Submitted By: Donovan Baarda (abo)
>Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: fnmatch doesn't escape '\' between [...]

Initial Comment:
The translate() function inside fnmatch doesn't 
escape '\' chars between '[' and ']' brackets when 
converting unix filename wildcards to a regular 
expression.

This means the '\' character behaves strangely when 
inside '['...']' or '[^'...']'. Depending on the 
character that follows, it can be interpreted in a 
wild variety of ways, including escaping the 
closing ']' and failing the re.compile. This was 
encountered when using fnmatch on windoze where 
os.sep='\'. Note that the docs say os.sep is not 
treated specially by fnmatch.

The fix required is to escape '\' in 'stuff' inside 
translate(). This is easiest done using stuff.replace
('\','\\'). A patch is attached...

----------------------------------------------------------------------

Comment By: Donovan Baarda (abo)
Date: 2001-03-18 21:26

Message:
Logged In: YES 
user_id=10273

Hmmm. that didn't work... I'll try again, but if it still 
doesn't work, use the one discribed as "fnmatch patch 
for '\' in '[...]'".

----------------------------------------------------------------------

Comment By: Donovan Baarda (abo)
Date: 2001-03-18 21:23

Message:
Logged In: YES 
user_id=10273

Due to potential confusion over which patch is the new one, 
I've deleted the old patch...

----------------------------------------------------------------------

Comment By: Donovan Baarda (abo)
Date: 2001-03-18 21:21

Message:
Logged In: YES 
user_id=10273

No sooner did I submit this, than I saw a neat way to make 
this small portion of code even neater and faster... new 
patch attached.

This patch trims 4 redundant lines and should be a fraction 
faster.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=409651&group_id=5470