Skip to content

Commit

Permalink
Merge 9c5e49e into a377df0
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Feb 10, 2019
2 parents a377df0 + 9c5e49e commit 94e760f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
12 changes: 9 additions & 3 deletions CHANGELOG.md
Expand Up @@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.3.0] - 2018-01-30
## [2.3.1] - 2019-02-10

### Fixed

- Add encoding check in OSFS.validatepath

## [2.3.0] - 2019-01-30

### Fixed

Expand All @@ -15,13 +21,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- FS.hash method

## [2.2.1] - 2018-01-06
## [2.2.1] - 2019-01-06

### Fixed

- `Registry.install` returns its argument.

## [2.2.0] - 2018-01-01
## [2.2.0] - 2019-01-01

A few methods have been renamed for greater clarity (but functionality remains the same).

Expand Down
2 changes: 1 addition & 1 deletion fs/_version.py
@@ -1,3 +1,3 @@
"""Version, used in module and setup.py.
"""
__version__ = "2.3.0"
__version__ = "2.3.1"
14 changes: 14 additions & 0 deletions fs/osfs.py
Expand Up @@ -627,3 +627,17 @@ def setinfo(self, path, info):
if accessed is not None or modified is not None:
with convert_os_errors("setinfo", path):
os.utime(sys_path, (accessed, modified))

def validatepath(self, path):
# type: (Text) -> Text
"""Check path may be encoded, in addition to usual checks."""
try:
fsencode(path)
except UnicodeEncodeError as error:
raise errors.InvalidCharsInPath(
path,
msg="path '{path}' could not be encoded for the filesystem (check LANG env var); {error}".format(
path=path, error=error
),
)
return super(OSFS, self).validatepath(path)
26 changes: 18 additions & 8 deletions tests/test_osfs.py
@@ -1,3 +1,4 @@
# coding: utf-8
from __future__ import unicode_literals

import errno
Expand Down Expand Up @@ -68,23 +69,23 @@ def test_not_exists(self):
with self.assertRaises(errors.CreateFailed):
fs = osfs.OSFS("/does/not/exists/")

@unittest.skipIf(osfs.sendfile is None, 'sendfile not supported')
@unittest.skipIf(osfs.sendfile is None, "sendfile not supported")
def test_copy_sendfile(self):
# try copying using sendfile
with mock.patch.object(osfs, 'sendfile') as sendfile:
sendfile.side_effect = OSError(errno.ENOTSUP, 'sendfile not supported')
with mock.patch.object(osfs, "sendfile") as sendfile:
sendfile.side_effect = OSError(errno.ENOTSUP, "sendfile not supported")
self.test_copy()
# check other errors are transmitted
self.fs.touch('foo')
with mock.patch.object(osfs, 'sendfile') as sendfile:
self.fs.touch("foo")
with mock.patch.object(osfs, "sendfile") as sendfile:
sendfile.side_effect = OSError(errno.EWOULDBLOCK)
with self.assertRaises(OSError):
self.fs.copy('foo', 'foo_copy')
self.fs.copy("foo", "foo_copy")
# check parent exist and is dir
with self.assertRaises(errors.ResourceNotFound):
self.fs.copy('foo', 'spam/eggs')
self.fs.copy("foo", "spam/eggs")
with self.assertRaises(errors.DirectoryExpected):
self.fs.copy('foo', 'foo_copy/foo')
self.fs.copy("foo", "foo_copy/foo")

def test_create(self):
"""Test create=True"""
Expand Down Expand Up @@ -131,3 +132,12 @@ def test_symlinks(self):
bar_info = self.fs.getinfo("bar", namespaces=["link", "lstat"])
self.assertIn("link", bar_info.raw)
self.assertIn("lstat", bar_info.raw)

def test_validatepath(self):
"""Check validatepath detects bad encodings."""

with mock.patch("fs.osfs.fsencode") as fsencode:
fsencode.side_effect = lambda error: "–".encode("ascii")
with self.assertRaises(errors.InvalidCharsInPath):
with self.fs.open("13 – Marked Register.pdf", "wb") as fh:
fh.write(b"foo")

0 comments on commit 94e760f

Please sign in to comment.