[issue9584] Allow curly braces in fnmatch

Antoine Pitrou report at bugs.python.org
Fri Aug 13 12:23:14 CEST 2010


Antoine Pitrou <pitrou at free.fr> added the comment:

Thanks for the patch.

+            if j < n and pat[j] == '}':
+                j = j+1

I don't get what the purpose of these two lines is. Forbid empty patterns?

+            while i < n and pat[j] != '}':
+                j = j+1

You probably mean "while j < n" instead of "while i < n".
Regardless, it's simpler to use "j = pat.find('}', j)".

You should also add a test for unmatched braces. Currently:

$ ./python -c "import fnmatch; print(fnmatch.translate('{x'))"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/antoine/py3k/__svn__/Lib/fnmatch.py", line 129, in translate
    while i < n and pat[j] != '}':
IndexError: string index out of range

----------
nosy: +pitrou

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9584>
_______________________________________


More information about the Python-bugs-list mailing list