From 1504d1fffb3f75ed0177820aa37ac53ea4ef7b4e Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Thu, 12 Oct 2017 17:44:40 -0400 Subject: [PATCH 1/2] Add fix for windwos paths * Fixes #865 --- pipenv/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pipenv/utils.py b/pipenv/utils.py index 3fea5fab..d7a6d630 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -340,6 +340,9 @@ def shellquote(s): """Prepares a string for the shell (on Windows too!)""" if s is None: return None + # Additional escaping for windows paths + if os.name == 'nt': + s = "{}".format(s.replace("\\", "\\\\")) return '"' + s.replace("'", "'\\''") + '"' @@ -850,8 +853,7 @@ def get_windows_path(*args): """Sanitize a path for windows environments Accepts an arbitrary list of arguments and makes a clean windows path""" - clean_path = os.path.join(*args) - return os.path.normpath(clean_path) + return os.path.normpath(os.path.join(*args)) def find_windows_executable(bin_path, exe_name): From aeafce54a60c5c5fa8df941df800449051c064bb Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Sun, 15 Oct 2017 19:45:54 -0400 Subject: [PATCH 2/2] Add tests for windows paths with spaces --- tests/test_utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index e68d9888..176e94ef 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import os import pytest from mock import patch, Mock @@ -165,3 +166,10 @@ class TestUtils: run_ret.out = version_output mocked_delegator.return_value = run_ret assert pipenv.utils.python_version('some/path') == version + + @pytest.mark.windows + @pytest.mark.skipif(os.name != 'nt', reason='Windows test only') + def test_windows_shellquote(self): + test_path = 'C:\Program Files\Python36\python.exe' + expected_path = '"C:\\\\Program Files\\\\Python36\\\\python.exe"' + assert pipenv.utils.shellquote(test_path) == expected_path