From 7f956e2f726933223fede7858740edfaf53cb854 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Mon, 31 Dec 2018 07:46:47 +0100 Subject: [PATCH] version parsing: fix errors with 3.0.0_pre1 (!1735) Python < 3.6 randomized the order of keys in dictionaries, unless OrderedDict was used. Use OrderedDict to store the version suffixes. When the order was randomized, the valid version string 3.0.0_pre1 did not always pass the validation check. The suffix "pre" should always be detected as such, but with the random order, it was sometimes detected as "p" suffix (see below). The following letters "re" are not a valid suffix_no (the number expected to follow the suffix) and so it failed. suffixes = { "pre": ["pre", ...], "post": ["p". ...] } --- pmb/parse/version.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pmb/parse/version.py b/pmb/parse/version.py index a78441eb..ee7dc196 100644 --- a/pmb/parse/version.py +++ b/pmb/parse/version.py @@ -16,6 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with pmbootstrap. If not, see . """ +import collections """ In order to stay as compatible to Alpine's apk as possible, this code @@ -122,10 +123,11 @@ def parse_suffix(rest): C equivalent: get_token(), case TOKEN_SUFFIX """ - suffixes = { - "pre": ["alpha", "beta", "pre", "rc"], - "post": ["cvs", "svn", "git", "hg", "p"] - } + + suffixes = collections.OrderedDict([ + ("pre", ["alpha", "beta", "pre", "rc"]), + ("post", ["cvs", "svn", "git", "hg", "p"]), + ]) for name, suffixes in suffixes.items(): for i, suffix in enumerate(suffixes):