Commits

Antoine Pitrou committed fbfa66a

Fix suffix for filenames starting or ending with a dot.

  • Participants
  • Parent commits a8031aa
  • Branches pep428

Comments (0)

Files changed (2)

     @property
     def suffix(self):
         """The final component's last suffix, if any."""
-        basename = self.name
-        if basename == '' or basename == '.':
-            return ''
+        basename = self.name.strip('.')
         i = basename.rfind('.')
         if i == -1:
             return ''

File test_pathlib.py

         P = self.cls
         self.assertEqual(P('').suffix, '')
         self.assertEqual(P('.').suffix, '')
+        self.assertEqual(P('..').suffix, '')
         self.assertEqual(P('/').suffix, '')
         self.assertEqual(P('a/b').suffix, '')
         self.assertEqual(P('/a/b').suffix, '')
         self.assertEqual(P('/a/b/.').suffix, '')
         self.assertEqual(P('a/b.py').suffix, '.py')
         self.assertEqual(P('/a/b.py').suffix, '.py')
+        self.assertEqual(P('a/.hgrc').suffix, '')
+        self.assertEqual(P('/a/.hgrc').suffix, '')
+        self.assertEqual(P('a/.hg.rc').suffix, '.rc')
+        self.assertEqual(P('/a/.hg.rc').suffix, '.rc')
         self.assertEqual(P('a/b.tar.gz').suffix, '.gz')
         self.assertEqual(P('/a/b.tar.gz').suffix, '.gz')
+        self.assertEqual(P('a/Some name ending with a dot.').suffix, '')
+        self.assertEqual(P('/a/Some name ending with a dot.').suffix, '')
 
     def test_suffixes_common(self):
         P = self.cls
         self.assertEqual(P('c:/a/b').suffix, '')
         self.assertEqual(P('c:a/b.py').suffix, '.py')
         self.assertEqual(P('c:/a/b.py').suffix, '.py')
+        self.assertEqual(P('c:a/.hgrc').suffix, '')
+        self.assertEqual(P('c:/a/.hgrc').suffix, '')
+        self.assertEqual(P('c:a/.hg.rc').suffix, '.rc')
+        self.assertEqual(P('c:/a/.hg.rc').suffix, '.rc')
         self.assertEqual(P('c:a/b.tar.gz').suffix, '.gz')
         self.assertEqual(P('c:/a/b.tar.gz').suffix, '.gz')
+        self.assertEqual(P('c:a/Some name ending with a dot.').suffix, '')
+        self.assertEqual(P('c:/a/Some name ending with a dot.').suffix, '')
         self.assertEqual(P('//My.py/Share.php').suffix, '')
         self.assertEqual(P('//My.py/Share.php/a/b').suffix, '')