Skip to content

Commit 0109970

Browse files
committed
Merged revisions 74475 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r74475 | gregory.p.smith | 2009-08-16 11:52:58 -0700 (Sun, 16 Aug 2009) | 2 lines Issue 6665: Fix fnmatch to properly match filenames with newlines in them. ........
1 parent c3b2ae4 commit 0109970

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

Lib/fnmatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,4 @@ def translate(pat):
113113
res = '%s[%s]' % (res, stuff)
114114
else:
115115
res = res + re.escape(c)
116-
return res + "$"
116+
return res + '\Z(?ms)'

Lib/test/test_fnmatch.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,18 @@ def test_fnmatch(self):
3232
check('a', 'b', 0)
3333

3434
# these test that '\' is handled correctly in character sets;
35-
# see SF bug #???
35+
# see SF bug #409651
3636
check('\\', r'[\]')
3737
check('a', r'[!\]')
3838
check('\\', r'[!\]', 0)
3939

40+
# test that filenames with newlines in them are handled correctly.
41+
# http://bugs.python.org/issue6665
42+
check('foo\nbar', 'foo*')
43+
check('foo\nbar\n', 'foo*')
44+
check('\nfoo', 'foo*', False)
45+
check('\n', '*')
46+
4047
def test_mix_bytes_str(self):
4148
self.assertRaises(TypeError, fnmatch, 'test', b'*')
4249
self.assertRaises(TypeError, fnmatch, b'test', '*')
@@ -46,6 +53,8 @@ def test_mix_bytes_str(self):
4653
def test_bytes(self):
4754
self.check_match(b'test', b'te*')
4855
self.check_match(b'test\xff', b'te*\xff')
56+
self.check_match(b'foo\nbar', b'foo*')
57+
4958

5059
def test_main():
5160
support.run_unittest(FnmatchTestCase)

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ C-API
6565
Library
6666
-------
6767

68+
- Issue #6665: Fix fnmatch to properly match filenames with newlines in them.
69+
6870
- Issue #1135: Add the XView and YView mix-ins to avoid duplicating
6971
the xview* and yview* methods.
7072

0 commit comments

Comments
 (0)