mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
bpo-32775: Fix regular expression warnings in fnmatch. (#5583)
fnmatch.translate() no longer produces patterns which contain set operations. Sets starting with '[' or containing '--', '&&', '~~' or '||' will be interpreted differently in regular expressions in future versions. Currently they emit warnings. fnmatch.translate() now avoids producing patterns containing such sets by accident.
This commit is contained in:
parent
feaefc7f60
commit
23cdbfa744
3 changed files with 38 additions and 2 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import unittest
|
||||
import os
|
||||
import warnings
|
||||
|
||||
from fnmatch import fnmatch, fnmatchcase, translate, filter
|
||||
|
||||
|
|
@ -83,6 +84,17 @@ class FnmatchTestCase(unittest.TestCase):
|
|||
check('usr/bin', 'usr\\bin', normsep)
|
||||
check('usr\\bin', 'usr\\bin')
|
||||
|
||||
def test_warnings(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('error', Warning)
|
||||
check = self.check_match
|
||||
check('[', '[[]')
|
||||
check('&', '[a&&b]')
|
||||
check('|', '[a||b]')
|
||||
check('~', '[a~~b]')
|
||||
check(',', '[a-z+--A-Z]')
|
||||
check('.', '[a-z--/A-Z]')
|
||||
|
||||
|
||||
class TranslateTestCase(unittest.TestCase):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue