Skip to content

Commit b103ab6

Browse files
committed
Update regex in 'convert' to match only strings with numbers, fixes python-semver#60
1 parent 2a122ac commit b103ab6

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

semver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def parse_version_info(version):
130130

131131
def _nat_cmp(a, b):
132132
def convert(text):
133-
return int(text) if re.match('[0-9]+', text) else text
133+
return int(text) if re.match('^[0-9]+$', text) else text
134134

135135
def split_key(key):
136136
return [convert(c) for c in key.split('.')]

tests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,10 @@ def test_should_compare_version_dictionaries():
331331
assert v1 < v4
332332
assert v1 <= v4
333333
assert not(v1 == v4)
334+
335+
336+
def test_should_compare_prerelease_with_numbers_and_letters():
337+
v1 = VersionInfo(major=1, minor=9, patch=1, prerelease='1unms', build=None)
338+
v2 = VersionInfo(major=1, minor=9, patch=1, prerelease=None, build='1asd')
339+
assert v1 < v2
340+
assert compare("1.9.1-1unms", "1.9.1+1") == -1

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy