From a7e53e203cb13b866afde69899928d20236072bb Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Thu, 18 Feb 2021 14:10:35 +0100 Subject: [PATCH] Fixed env var with password only: MPD_HOST=pass@ --- musicpd.py | 3 ++- test.py | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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() -- 2.39.5