From a3420f074de70e8cd6f3050e3351fa9b43db0102 Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Thu, 18 Feb 2021 14:18:31 +0100 Subject: [PATCH] More robust MPD_HOST parsing MPD_HOST=@ is handled correctly as empty --- musicpd.py | 2 +- test.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/musicpd.py b/musicpd.py index 34a2418..9b1d51b 100644 --- a/musicpd.py +++ b/musicpd.py @@ -309,7 +309,7 @@ class MPDClient: self.pwd = mpd_host_env[0] if mpd_host_env[1]: self.host = mpd_host_env[1] - else: + elif mpd_host_env[1]: # No password set but leading @ is an abstract socket self.host = '@'+mpd_host_env[1] else: diff --git a/test.py b/test.py index fc7e385..ecf62ff 100755 --- a/test.py +++ b/test.py @@ -68,6 +68,13 @@ class testEnvVar(unittest.TestCase): self.assertEqual(client.pwd, 'pa55w04d') self.assertEqual(client.host, 'localhost') + # Test badly formatted MPD_HOST + os.environ['MPD_HOST'] = '@' + with mock.patch('os.path.exists', return_value=False): + client = musicpd.MPDClient() + self.assertEqual(client.pwd, None) + self.assertEqual(client.host, 'localhost') + # Test unix socket extraction os.environ['MPD_HOST'] = 'pa55w04d@/unix/sock' client = musicpd.MPDClient() -- 2.39.5