diff options
author | Seth Morton <seth.m.morton@gmail.com> | 2019-02-27 18:51:58 -0800 |
---|---|---|
committer | Seth Morton <seth.m.morton@gmail.com> | 2019-02-27 21:40:07 -0800 |
commit | 7f08e4b8d73f6439156ee0235af1b0fbe71ba408 (patch) | |
tree | bd54f6f461fffc233c482fc218a2acd16e59cbe6 | |
parent | 7becf791ce39ac3c00a63f6621f61f11f8af47e0 (diff) | |
download | natsort-7f08e4b8d73f6439156ee0235af1b0fbe71ba408.tar.gz |
Fix path splitter issue on Windows
If a unix-style absolute path is given to the path_splitter on Windows,
the first element was a unix-style path separator and not a Windows path
sparator. This has been fixed.
The docstring has updated to be true for all OSes.
Unit tests are updated to account for this change.
-rw-r--r-- | natsort/utils.py | 9 | ||||
-rw-r--r-- | tests/test_natsort_keygen.py | 6 |
2 files changed, 10 insertions, 5 deletions
diff --git a/natsort/utils.py b/natsort/utils.py index 4db0f80..61387d3 100644 --- a/natsort/utils.py +++ b/natsort/utils.py @@ -47,6 +47,7 @@ from itertools import chain as ichain from operator import methodcaller from os import curdir as os_curdir from os import pardir as os_pardir +from os import sep as os_sep from os.path import split as path_split from os.path import splitext as path_splitext from unicodedata import normalize @@ -743,8 +744,8 @@ def path_splitter(s, _d_match=re.compile(r"\.\d").match): Examples -------- - >>> tuple(path_splitter("/this/thing.ext")) - ({u}'/', {u}'this', {u}'thing', {u}'.ext') + >>> tuple(path_splitter("this/thing.ext")) + ({u}'this', {u}'thing', {u}'.ext') """ if has_pathlib and isinstance(s, PurePath): @@ -763,8 +764,10 @@ def path_splitter(s, _d_match=re.compile(r"\.\d").match): # This last append is the base path. # Only append if the string is non-empty. + # Make sure the proper path separator for this OS is used + # no matter what was actually given. if path_location: - p_appendleft(path_location) + p_appendleft(py23_str(os_sep)) # Now, split off the file extensions using a similar method to above. # Continue splitting off file extensions until we reach a decimal number diff --git a/tests/test_natsort_keygen.py b/tests/test_natsort_keygen.py index baa4c3e..0cf5fa6 100644 --- a/tests/test_natsort_keygen.py +++ b/tests/test_natsort_keygen.py @@ -5,10 +5,12 @@ See the README or the natsort homepage for more details. """ from __future__ import print_function, unicode_literals +import os + import pytest from natsort import natsort_key, natsort_keygen, natsorted, ns from natsort.compat.locale import get_strxfrm, null_string_locale -from natsort.compat.py23 import PY_VERSION +from natsort.compat.py23 import PY_VERSION, py23_str @pytest.fixture @@ -72,7 +74,7 @@ def test_natsort_keygen_returns_natsort_key_that_parses_input(alg, expected): ns.PATH | ns.GROUPLETTERS, ( (("", 6, "aA--", 5, "..", 34, "ee++", 1),), - (("//",), ("fFoollddeerr ((", 1, "))"), ("fFoooo",)), + ((2 * py23_str(os.sep),), ("fFoollddeerr ((", 1, "))"), ("fFoooo",)), (("", 56.7),), ), ), |