[PATCH 2/2] Reject timestamp versions in the VERSION_DIGITS regex
David Shea
dshea at redhat.com
Fri Feb 20 16:51:56 UTC 2015
---
pyanaconda/packaging/__init__.py | 5 ---
pyanaconda/regexes.py | 5 ++-
tests/regex_tests/version_digits_test.py | 57 ++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+), 6 deletions(-)
create mode 100644 tests/regex_tests/version_digits_test.py
diff --git a/pyanaconda/packaging/__init__.py b/pyanaconda/packaging/__init__.py
index e4a9a63..84a7066 100644
--- a/pyanaconda/packaging/__init__.py
+++ b/pyanaconda/packaging/__init__.py
@@ -395,11 +395,6 @@ class Payload(object):
except ConfigParser.Error:
pass
- # If the version looks like a timestamp, assume it's rawhide
- # plz change before Fedora version 9999999
- if version[:8].isdigit():
- version = "rawhide"
-
log.debug("got a release version of %s", version)
return version
diff --git a/pyanaconda/regexes.py b/pyanaconda/regexes.py
index b4e52a3..f3ee8ae 100644
--- a/pyanaconda/regexes.py
+++ b/pyanaconda/regexes.py
@@ -134,4 +134,7 @@ URL_PARSE = re.compile(r'^(?P<protocol>' + URL_SCHEME_PATTERN_WITHOUT_ANCHORS +
REPO_NAME_VALID = re.compile(r'^[a-zA-Z0-9_.:-]+$')
# Product Version string, just the starting numbers like 21 or 21.1
-VERSION_DIGITS = r'([\d.]+)'
+# If a version number starts with 8 or more digits, it's assumed to be a
+# timestamp, and thus not a version. The ?! bit at the end causes such a
+# string to be rejected instead of matching the first 7 digits.
+VERSION_DIGITS = re.compile(r'^((?:\d{1,7}\.)*\d{1,7}(?!\d))')
diff --git a/tests/regex_tests/version_digits_test.py b/tests/regex_tests/version_digits_test.py
new file mode 100644
index 0000000..8e35a14
--- /dev/null
+++ b/tests/regex_tests/version_digits_test.py
@@ -0,0 +1,57 @@
+#!/usr/bin/python2
+# vim:set fileencoding=utf-8
+#
+# Copyright (C) 2015 Red Hat, Inc.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# the GNU General Public License v.2, or (at your option) any later version.
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY expressed or implied, including the implied warranties of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details. You should have received a copy of the
+# GNU General Public License along with this program; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
+# source code or documentation are not subject to the GNU General Public
+# License and may only be used or replicated with the express permission of
+# Red Hat, Inc.
+#
+# Red Hat Author(s): David Shea <dshea at redhat.com>
+#
+
+import unittest
+
+from regexcheck import regex_group
+from pyanaconda.regexes import VERSION_DIGITS
+
+class VersionDigitsTestCase(unittest.TestCase):
+ def version_test(self):
+ """ Test things that are and are not version numbers. """
+
+ # The regex just checks that the start of a string looks like a
+ # version number, so strings can have extra non-version things on
+ # the end that will be ignored.
+ tests = [
+
+ # Straightforward, just a version number
+ ( "1.0", ("1.0",) ),
+ ( "22", ("22",) ),
+ ( "1.2.3.4", ("1.2.3.4",) ),
+
+ # Version number with extra
+ ( "1.0.whatever", ("1.0",) ),
+ ( "22 Server", ("22",) ),
+ ( "1..0", ("1",) ),
+
+ # Not at all a version number
+ ( ".0", None ),
+ ( "rawhide", None),
+ # timestamps
+ ( "20150401", None),
+ ( "20150401.0", None),
+
+ ]
+
+ if not regex_group(VERSION_DIGITS, tests):
+ self.fail()
--
2.1.0
More information about the anaconda-patches
mailing list