diff options
-rw-r--r-- | pbr/tests/test_util.py | 67 | ||||
-rw-r--r-- | pbr/util.py | 2 | ||||
-rw-r--r-- | releasenotes/notes/fix-mapping-value-explode-with-equal-sign-41bf822fa4dd0e68.yaml | 7 |
3 files changed, 62 insertions, 14 deletions
diff --git a/pbr/tests/test_util.py b/pbr/tests/test_util.py index 370a7de..6c490a9 100644 --- a/pbr/tests/test_util.py +++ b/pbr/tests/test_util.py @@ -23,6 +23,19 @@ from pbr.tests import base from pbr import util +def config_from_ini(ini): + config = {} + if sys.version_info >= (3, 2): + parser = configparser.ConfigParser() + else: + parser = configparser.SafeConfigParser() + ini = textwrap.dedent(six.u(ini)) + parser.readfp(io.StringIO(ini)) + for section in parser.sections(): + config[section] = dict(parser.items(section)) + return config + + class TestExtrasRequireParsingScenarios(base.BaseTestCase): scenarios = [ @@ -64,20 +77,8 @@ class TestExtrasRequireParsingScenarios(base.BaseTestCase): {} })] - def config_from_ini(self, ini): - config = {} - if sys.version_info >= (3, 2): - parser = configparser.ConfigParser() - else: - parser = configparser.SafeConfigParser() - ini = textwrap.dedent(six.u(ini)) - parser.readfp(io.StringIO(ini)) - for section in parser.sections(): - config[section] = dict(parser.items(section)) - return config - def test_extras_parsing(self): - config = self.config_from_ini(self.config_text) + config = config_from_ini(self.config_text) kwargs = util.setup_cfg_to_setup_kwargs(config) self.assertEqual(self.expected_extra_requires, @@ -89,3 +90,43 @@ class TestInvalidMarkers(base.BaseTestCase): def test_invalid_marker_raises_error(self): config = {'extras': {'test': "foo :bad_marker>'1.0'"}} self.assertRaises(SyntaxError, util.setup_cfg_to_setup_kwargs, config) + + +class TestMapFieldsParsingScenarios(base.BaseTestCase): + + scenarios = [ + ('simple_project_urls', { + 'config_text': """ + [metadata] + project_urls = + Bug Tracker = https://bugs.launchpad.net/pbr/ + Documentation = https://docs.openstack.org/pbr/ + Source Code = https://git.openstack.org/cgit/openstack-dev/pbr/ + """, # noqa: E501 + 'expected_project_urls': { + 'Bug Tracker': 'https://bugs.launchpad.net/pbr/', + 'Documentation': 'https://docs.openstack.org/pbr/', + 'Source Code': 'https://git.openstack.org/cgit/openstack-dev/pbr/', # noqa: E501 + }, + }), + ('query_parameters', { + 'config_text': """ + [metadata] + project_urls = + Bug Tracker = https://bugs.launchpad.net/pbr/?query=true + Documentation = https://docs.openstack.org/pbr/?foo=bar + Source Code = https://git.openstack.org/cgit/openstack-dev/pbr/commit/?id=hash + """, # noqa: E501 + 'expected_project_urls': { + 'Bug Tracker': 'https://bugs.launchpad.net/pbr/?query=true', + 'Documentation': 'https://docs.openstack.org/pbr/?foo=bar', + 'Source Code': 'https://git.openstack.org/cgit/openstack-dev/pbr/commit/?id=hash', # noqa: E501 + }, + }), + ] + + def test_project_url_parsing(self): + config = config_from_ini(self.config_text) + kwargs = util.setup_cfg_to_setup_kwargs(config) + + self.assertEqual(self.expected_project_urls, kwargs['project_urls']) diff --git a/pbr/util.py b/pbr/util.py index 63e913d..4c76081 100644 --- a/pbr/util.py +++ b/pbr/util.py @@ -333,7 +333,7 @@ def setup_cfg_to_setup_kwargs(config, script_args=()): elif arg in MAP_FIELDS: in_cfg_map = {} for i in split_multiline(in_cfg_value): - k, v = i.split('=') + k, v = i.split('=', 1) in_cfg_map[k.strip()] = v.strip() in_cfg_value = in_cfg_map elif arg in BOOL_FIELDS: diff --git a/releasenotes/notes/fix-mapping-value-explode-with-equal-sign-41bf822fa4dd0e68.yaml b/releasenotes/notes/fix-mapping-value-explode-with-equal-sign-41bf822fa4dd0e68.yaml new file mode 100644 index 0000000..3898587 --- /dev/null +++ b/releasenotes/notes/fix-mapping-value-explode-with-equal-sign-41bf822fa4dd0e68.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Fix mapping error on values who contains a literal ``=``. Example when + setup.cfg contains content like the following project urls configuration + "project_urls = Documentation = http://foo.bar/?badge=latest". + https://bugs.launchpad.net/pbr/+bug/1817592 |