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)
downloadpbr-a27f51242b041f8afd79d4fa2d4d6eaf1dda9f0c.tar.gz
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
-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):
(self.option_value.lower() in options.TRUE_VALUES
or self.env_value is not None))
-_changelog_content = """04316fe\x00Make python\x00 (review/monty_taylor/27519)
+_changelog_content = """7780758\x00Break parser\x00 (tag: 1_foo.1)
+04316fe\x00Make python\x00 (review/monty_taylor/27519)
378261a\x00Add an integration test script.\x00
3c373ac\x00Merge "Lib\x00 (HEAD, tag: 2013.2.rc2, tag: 2013.2, mile-proposed)
182feb3\x00Fix pip invocation for old versions of pip.\x00 (tag: 0.5.17)
@@ -159,6 +160,7 @@ class GitLogsTest(base.BaseTestCase):
self.assertNotIn("ev)il", changelog_contents)
self.assertNotIn("e(vi)l", changelog_contents)
self.assertNotIn('Merge "', changelog_contents)
+ self.assertNotIn('1_foo.1', changelog_contents)
def test_generate_authors(self):
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):
ever released - we're treating that as a critical bug that we ever
made them and have stopped doing that.
"""
+
+ try:
+ return klass._from_pip_string_unsafe(version_string)
+ except IndexError:
+ raise ValueError("Invalid version %r" % version_string)
+
+ @classmethod
+ def _from_pip_string_unsafe(klass, version_string):
# Versions need to start numerically, ignore if not
if not version_string[:1].isdigit():
raise ValueError("Invalid version %r" % version_string)