diff --git a/jenkins/__init__.py b/jenkins/__init__.py index 4105c89..77ffd31 100755 --- a/jenkins/__init__.py +++ b/jenkins/__init__.py @@ -544,6 +544,7 @@ class Jenkins(object): """ url = '/'.join((item, INFO)).lstrip('/') + url = quote(url) if query: url += query try: diff --git a/tests/jobs/base.py b/tests/jobs/base.py index 0ddf67b..4b8bbfa 100644 --- a/tests/jobs/base.py +++ b/tests/jobs/base.py @@ -39,6 +39,16 @@ class JenkinsGetJobsTestBase(JenkinsJobsTestBase): ] ) + jobs_in_unsafe_name_folders = copy.deepcopy(jobs_in_folder) + jobs_in_unsafe_name_folders[1].insert( + 0, {'name': 'my spaced folder', 'jobs': None}) + jobs_in_unsafe_name_folders.append( + # my_folder1/my\ spaced\ folder jobs + [ + {'name': 'my job 5'} + ] + ) + def build_jobs_list_responses(jobs_list, server_url): responses = [] diff --git a/tests/jobs/test_getall.py b/tests/jobs/test_getall.py index fad2570..bc0f549 100644 --- a/tests/jobs/test_getall.py +++ b/tests/jobs/test_getall.py @@ -59,3 +59,20 @@ class JenkinsGetAllJobsTest(JenkinsGetJobsTestBase): self.assertEqual(len(expected_fullnames), len(jobs_info)) got_fullnames = [job[u"fullname"] for job in jobs_info] self.assertEqual(expected_fullnames, got_fullnames) + + @patch.object(jenkins.Jenkins, 'jenkins_open') + def test_unsafe_chars(self, jenkins_mock): + response = build_jobs_list_responses( + self.jobs_in_unsafe_name_folders, 'http://example.com/') + jenkins_mock.side_effect = iter(response) + + jobs_info = self.j.get_all_jobs() + + expected_fullnames = [ + u"my_job1", u"my_job2", + u"my_folder1/my_job3", u"my_folder1/my_job4", + u"my_folder1/my spaced folder/my job 5" + ] + self.assertEqual(len(expected_fullnames), len(jobs_info)) + got_fullnames = [job[u"fullname"] for job in jobs_info] + self.assertEqual(expected_fullnames, got_fullnames)