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):
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()