]> kaliko git repositories - python-musicpd.git/commitdiff
More robust MPD_HOST parsing
authorKaliko Jack <kaliko@azylum.org>
Thu, 18 Feb 2021 13:18:31 +0000 (14:18 +0100)
committerKaliko Jack <kaliko@azylum.org>
Thu, 18 Feb 2021 13:18:31 +0000 (14:18 +0100)
MPD_HOST=@ is handled correctly as empty

musicpd.py
test.py

index 34a2418c36d33a4626e8a4dbcde3e6def2dbc67f..9b1d51b7477b565a0d72a0aa84199e31f741f063 100644 (file)
@@ -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 fc7e385c245f3a96481159f13381ea65b2c169c4..ecf62ffb6c70e70fc28abc8f668644c00003aa3a 100755 (executable)
--- 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()