Skip to content

Commit

Permalink
Fixed handling of trailing path separators in lstat
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbean-bremen committed Jan 3, 2018
1 parent 32eccbd commit 39c486f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyfakefs/fake_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2013,7 +2013,7 @@ def lresolve(self, path):
# remove trailing separator
sep = self._path_separator(path)
alt_sep = self._alternative_path_separator(path)
if path.endswith(sep) or (alt_sep and path.endswith(alt_sep)):
while path.endswith(sep) or (alt_sep and path.endswith(alt_sep)):
path = path[:-1]
path = self._original_path(path)

Expand Down
9 changes: 9 additions & 0 deletions tests/fake_os_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ def test_lstat_size_windows(self):
self.assertEqual(0,
self.os.lstat(link_path)[stat.ST_SIZE])

def test_lstat_trailing_sep(self):
# regression test for #342
stat = self.os.lstat(self.base_path)
self.assertEqual(stat, self.os.lstat(
self.base_path + self.filesystem.path_separator))
self.assertEqual(stat, self.os.lstat(
self.base_path + self.filesystem.path_separator
+ self.filesystem.path_separator))

@unittest.skipIf(sys.version_info < (3, 3),
'file descriptor as path new in Python 3.3')
def test_lstat_uses_open_fd_as_path(self):
Expand Down

0 comments on commit 39c486f

Please sign in to comment.