From: Kaliko Jack Date: Tue, 6 Jul 2021 10:55:40 +0000 (+0200) Subject: Raises an exception if command contains '\n' X-Git-Tag: v0.7.0~2 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=a8a2060756f1811f59febe11bd75521989674b83;p=python-musicpd.git Raises an exception if command contains '\n' --- diff --git a/CHANGES.txt b/CHANGES.txt index 5f2f7a8..71e92e2 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 diff --git a/musicpd.py b/musicpd.py index 3fd7201..68cd862 100644 --- a/musicpd.py +++ b/musicpd.py @@ -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 7f1890f..840bd47 100755 --- 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()