From: Kaliko Jack Date: Thu, 18 Feb 2021 13:18:31 +0000 (+0100) Subject: More robust MPD_HOST parsing X-Git-Tag: v0.6.0~12 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=a3420f074de70e8cd6f3050e3351fa9b43db0102;p=python-musicpd.git More robust MPD_HOST parsing MPD_HOST=@ is handled correctly as empty --- 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()