Fix directories not normalised when trailing slash is present
This commit is contained in:
parent
ad55d4011b
commit
122a59cbb6
@ -46,13 +46,21 @@ class Normalisename:
|
|||||||
return [self.normalise(path) for path in paths]
|
return [self.normalise(path) for path in paths]
|
||||||
|
|
||||||
def normalise(self, path):
|
def normalise(self, path):
|
||||||
|
path = self.strip_trailing_slash(path)
|
||||||
directory = dirname(path)
|
directory = dirname(path)
|
||||||
filename = basename(path)
|
filename = basename(path)
|
||||||
normalpath = joinpath(directory, self.normalname(filename))
|
normalpath = joinpath(directory, self.normalname(filename))
|
||||||
|
|
||||||
if path != normalpath:
|
if path != normalpath:
|
||||||
self.operation(path, normalpath) # pylint: disable=not-callable
|
self.operation(path, normalpath) # pylint: disable=not-callable
|
||||||
return normalpath
|
return normalpath
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def strip_trailing_slash(path):
|
||||||
|
if path[-1] == '/':
|
||||||
|
path = path[:-1]
|
||||||
|
return path
|
||||||
|
|
||||||
def normalname(self, filename):
|
def normalname(self, filename):
|
||||||
return unidecode(
|
return unidecode(
|
||||||
''.join(
|
''.join(
|
||||||
|
3
test.py
3
test.py
@ -50,4 +50,5 @@ def test_dirname_is_not_changed(normalise, path):
|
|||||||
|
|
||||||
|
|
||||||
def test_name_with_trailing_slash_is_normalised(normalise):
|
def test_name_with_trailing_slash_is_normalised(normalise):
|
||||||
assert False
|
path = '/home/user/Desktop/cat directory/'
|
||||||
|
assert normalise(path) == f'/home/user/Desktop/cat{SEP}directory'
|
||||||
|
Loading…
Reference in New Issue
Block a user