From: Kaliko Jack Date: Thu, 18 Feb 2021 13:10:35 +0000 (+0100) Subject: Fixed env var with password only: MPD_HOST=pass@ X-Git-Tag: v0.6.0~13 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=a7e53e203cb13b866afde69899928d20236072bb;p=python-musicpd.git Fixed env var with password only: MPD_HOST=pass@ --- diff --git a/musicpd.py b/musicpd.py index 47eb7b5..34a2418 100644 --- a/musicpd.py +++ b/musicpd.py @@ -307,7 +307,8 @@ class MPDClient: if mpd_host_env[0]: # A password is actually set self.pwd = mpd_host_env[0] - self.host = mpd_host_env[1] + if mpd_host_env[1]: + self.host = mpd_host_env[1] else: # No password set but leading @ is an abstract socket self.host = '@'+mpd_host_env[1] diff --git a/test.py b/test.py index 449101b..fc7e385 100755 --- a/test.py +++ b/test.py @@ -61,6 +61,13 @@ class testEnvVar(unittest.TestCase): self.assertEqual(client.pwd, 'pa55w04d') self.assertEqual(client.host, 'example.org') + # Test password extraction (no host) + os.environ['MPD_HOST'] = 'pa55w04d@' + with mock.patch('os.path.exists', return_value=False): + client = musicpd.MPDClient() + self.assertEqual(client.pwd, 'pa55w04d') + self.assertEqual(client.host, 'localhost') + # Test unix socket extraction os.environ['MPD_HOST'] = 'pa55w04d@/unix/sock' client = musicpd.MPDClient()