Skip to content

Commit

Permalink
[1.7.x] Fixed #22256 -- Replaced bad fallback for missing PATH
Browse files Browse the repository at this point in the history
Thanks Baptiste Mispelon for the review.
Backport of acee46f from master.
  • Loading branch information
vegitron authored and claudep committed Mar 22, 2014
1 parent 07d4b3c commit 908bdea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion django/core/management/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def handle_extensions(extensions=('html',), ignored=('py',)):

def find_command(cmd, path=None, pathext=None):
if path is None:
path = os.environ.get('PATH', []).split(os.pathsep)
path = os.environ.get('PATH', '').split(os.pathsep)
if isinstance(path, six.string_types):
path = [path]
# check if there are funny path extensions for executables, e.g. Windows
Expand Down
16 changes: 15 additions & 1 deletion tests/user_commands/tests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import sys

from django.core import management
from django.core.management import CommandError
from django.core.management.utils import popen_wrapper
from django.core.management.utils import find_command, popen_wrapper
from django.test import SimpleTestCase
from django.utils import translation
from django.utils.six import StringIO
Expand Down Expand Up @@ -60,6 +61,19 @@ def test_configured_locale_preserved(self):
management.call_command('leave_locale_alone_true', stdout=out)
self.assertEqual(out.getvalue(), "pl\n")

def test_find_command_without_PATH(self):
"""
find_command should still work when the PATH environment variable
doesn't exist (#22256).
"""
current_path = os.environ.pop('PATH', None)

try:
self.assertIsNone(find_command('_missing_'))
finally:
if current_path is not None:
os.environ['PATH'] = current_path


class UtilsTests(SimpleTestCase):

Expand Down

0 comments on commit 908bdea

Please sign in to comment.