]> kaliko git repositories - python-musicpd.git/commitdiff
Raises an exception if command contains '\n'
authorKaliko Jack <kaliko@azylum.org>
Tue, 6 Jul 2021 10:55:40 +0000 (12:55 +0200)
committerKaliko Jack <kaliko@azylum.org>
Tue, 6 Jul 2021 10:55:40 +0000 (12:55 +0200)
CHANGES.txt
musicpd.py
test.py

index 5f2f7a8c0e4b0deb0381de4ee38fd0b6f42e1651..71e92e2339bf71dadca9a5362e4de36ac04d83d8 100644 (file)
@@ -4,7 +4,7 @@ python-musicpd Changes List
 Changes in 0.6.1
 ----------------
 
-* 
+* Raises an exception if command contains '\n'
 
 
 Changes in 0.6.0
index 3fd7201729c9f536262ca85ed1e76683d29873d0..68cd8625f3c71c4d7c510c7a461cb91883d62f71 100644 (file)
@@ -406,6 +406,8 @@ class MPDClient:
                 parts.append('{0!s}'.format(Range(arg)))
             else:
                 parts.append('"%s"' % escape(str(arg)))
+        if '\n' in ' '.join(parts):
+            raise CommandError('new line found in the command!')
         self._write_line(" ".join(parts))
 
     def _read_binary(self, amount):
diff --git a/test.py b/test.py
index 7f1890fe9f325ec1b4c5c450ea8048d8b5727cca..840bd4730dd03fd76c18677ba1fa876842e20a12 100755 (executable)
--- a/test.py
+++ b/test.py
@@ -582,5 +582,18 @@ class testConnection(unittest.TestCase):
             sock.connect.assert_called_with('/run/mpd/socket')
 
 
+class testException(unittest.TestCase):
+
+    def test_CommandError_on_newline(self):
+        os.environ['MPD_HOST'] = '/run/mpd/socket'
+        with mock.patch('musicpd.socket') as socket_mock:
+            sock = mock.MagicMock(name='socket')
+            socket_mock.socket.return_value = sock
+            cli = musicpd.MPDClient()
+            cli.connect()
+            with self.assertRaises(musicpd.CommandError):
+                cli.find('(album == "foo\nbar")')
+
+
 if __name__ == '__main__':
     unittest.main()