]> kaliko git repositories - python-musicpd.git/commitdiff
Fixed env var with password only: MPD_HOST=pass@
authorKaliko Jack <kaliko@azylum.org>
Thu, 18 Feb 2021 13:10:35 +0000 (14:10 +0100)
committerKaliko Jack <kaliko@azylum.org>
Thu, 18 Feb 2021 13:10:35 +0000 (14:10 +0100)
musicpd.py
test.py

index 47eb7b5cd3afc61306c50413b6835329163927f1..34a2418c36d33a4626e8a4dbcde3e6def2dbc67f 100644 (file)
@@ -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 449101b994f6c096b989cb9df0de3afbe5553064..fc7e385c245f3a96481159f13381ea65b2c169c4 100755 (executable)
--- 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()