Skip to content

Commit

Permalink
fix(to_version): assured it handles '0' correctly
Browse files Browse the repository at this point in the history
Previously, it could possibly take a '0' away from the start of a
version. Now this is definitely not possible anymore.

Fixes #3
  • Loading branch information
Byron committed Mar 12, 2015
1 parent 664d822 commit 4b9dbb2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/mako/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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), '')
Expand Down Expand Up @@ -823,6 +827,9 @@ def test_to_version():
('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)
Expand Down

0 comments on commit 4b9dbb2

Please sign in to comment.