From 4b9dbb28ff474661855f53143862b621e650f157 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 12 Mar 2015 11:39:55 +0100 Subject: [PATCH] fix(to_version): assured it handles '0' correctly Previously, it could possibly take a '0' away from the start of a version. Now this is definitely not possible anymore. Fixes #3 --- src/mako/lib/util.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index 7cfed4e368..83925a890d 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -683,10 +683,14 @@ def to_api_version(v): assert m, "Expected to find a version within '%s'" % v tokens = m.group(1).split('.') - for t in tokens[1:]: + up_to = len(tokens) + for t in reversed(tokens[1:]): if t == '0': - tokens.remove(t) - version = '.'.join(tokens) + up_to -= 1 + else: + break + + version = '.'.join(tokens[:up_to]) version = version.replace('.', 'd') remainder = v.replace(m.group(0), '') @@ -823,6 +827,9 @@ if __name__ == '__main__': ('v1beta2', '1_beta2'), ('v1sandbox', '1_sandbox'), ('v2.0', '2'), + ('v2.0.1', '2d0d1'), + ('v0.0', '0'), + ('v0.1.0', '0d1'), ('v2.0beta3', '2_beta3'),): res = to_api_version(v) assert res == want, "%s == %s" % (res, want)