summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Nortman <openstack@nortman.net>2016-04-13 21:05:07 -0400
committerRandall Nortman <openstack@nortman.net>2016-04-13 21:52:02 -0400
commita27f51242b041f8afd79d4fa2d4d6eaf1dda9f0c (patch)
tree7e842f827224b984f62eff8181dc97fddb449972
parentd4e29cb5d23e2bd1cf1b8a6b166b034279c764d7 (diff)
Handle IndexError during version string parsing1.9.1
Some odd version strings can cause SemanticVersion.from_pip_string() to raise IndexError. This change converts IndexError to ValueError. Change-Id: Ic3046817b6c5808c61c4a3bc3d912501e6a52274 Closes-Bug: #1570145
Notes
Notes (review): Code-Review+2: Jeremy Stanley <fungi@yuggoth.org> Code-Review+2: ChangBo Guo(gcb) <glongwave@gmail.com> Workflow+1: ChangBo Guo(gcb) <glongwave@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Thu, 14 Apr 2016 04:24:50 +0000 Reviewed-on: https://review.openstack.org/305550 Project: openstack-dev/pbr Branch: refs/heads/master
-rw-r--r--pbr/tests/test_setup.py4
-rw-r--r--pbr/version.py8
2 files changed, 11 insertions, 1 deletions
diff --git a/pbr/tests/test_setup.py b/pbr/tests/test_setup.py
index cd95c73..f3fcd40 100644
--- a/pbr/tests/test_setup.py
+++ b/pbr/tests/test_setup.py
@@ -99,7 +99,8 @@ class SkipFileWrites(base.BaseTestCase):
99 (self.option_value.lower() in options.TRUE_VALUES 99 (self.option_value.lower() in options.TRUE_VALUES
100 or self.env_value is not None)) 100 or self.env_value is not None))
101 101
102_changelog_content = """04316fe\x00Make python\x00 (review/monty_taylor/27519) 102_changelog_content = """7780758\x00Break parser\x00 (tag: 1_foo.1)
10304316fe\x00Make python\x00 (review/monty_taylor/27519)
103378261a\x00Add an integration test script.\x00 104378261a\x00Add an integration test script.\x00
1043c373ac\x00Merge "Lib\x00 (HEAD, tag: 2013.2.rc2, tag: 2013.2, mile-proposed) 1053c373ac\x00Merge "Lib\x00 (HEAD, tag: 2013.2.rc2, tag: 2013.2, mile-proposed)
105182feb3\x00Fix pip invocation for old versions of pip.\x00 (tag: 0.5.17) 106182feb3\x00Fix pip invocation for old versions of pip.\x00 (tag: 0.5.17)
@@ -159,6 +160,7 @@ class GitLogsTest(base.BaseTestCase):
159 self.assertNotIn("ev)il", changelog_contents) 160 self.assertNotIn("ev)il", changelog_contents)
160 self.assertNotIn("e(vi)l", changelog_contents) 161 self.assertNotIn("e(vi)l", changelog_contents)
161 self.assertNotIn('Merge "', changelog_contents) 162 self.assertNotIn('Merge "', changelog_contents)
163 self.assertNotIn('1_foo.1', changelog_contents)
162 164
163 def test_generate_authors(self): 165 def test_generate_authors(self):
164 author_old = u"Foo Foo <email@foo.com>" 166 author_old = u"Foo Foo <email@foo.com>"
diff --git a/pbr/version.py b/pbr/version.py
index d3fe401..619c432 100644
--- a/pbr/version.py
+++ b/pbr/version.py
@@ -142,6 +142,14 @@ class SemanticVersion(object):
142 ever released - we're treating that as a critical bug that we ever 142 ever released - we're treating that as a critical bug that we ever
143 made them and have stopped doing that. 143 made them and have stopped doing that.
144 """ 144 """
145
146 try:
147 return klass._from_pip_string_unsafe(version_string)
148 except IndexError:
149 raise ValueError("Invalid version %r" % version_string)
150
151 @classmethod
152 def _from_pip_string_unsafe(klass, version_string):
145 # Versions need to start numerically, ignore if not 153 # Versions need to start numerically, ignore if not
146 if not version_string[:1].isdigit(): 154 if not version_string[:1].isdigit():
147 raise ValueError("Invalid version %r" % version_string) 155 raise ValueError("Invalid version %r" % version_string)