Skip to content

Commit 0ae59a0

Browse files
committed
Fix VersionRange crash on not in range versions
Earlier, the check for whether the pairwise version constraints is in a valid sequence and if the given version is in that pairwise range was performed in a single condition. Upon failing the later case, it assumed the failure of earlier as well and crashed. Now, the later check is performed within the former condition. Fixes: #25 Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
1 parent 4dccdfb commit 0ae59a0

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

src/univers/version_constraint.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -444,20 +444,20 @@ def contains_version(version, constraints):
444444
if len(constraints) == 1:
445445
return version in constraints[0]
446446

447-
# If the "tested version" is equal to the any of the constraint version
448-
# where the constraint comparator is for equality (any of "=", "<=", or ">=")
449-
# then the "tested version" is in the range. Check is finished.
450-
for constraint in constraints:
451-
if "=" in constraint.comparator and version == constraint.version:
452-
return True
453-
454447
# If the "tested version" is equal to the any of the constraint version where
455448
# the constraint comparator is "=!" then the "tested version" is NOT in the
456449
# range. Check is finished.
457450
for constraint in constraints:
458451
if "!=" in constraint.comparator and version == constraint.version:
459452
return False
460453

454+
# If the "tested version" is equal to the any of the constraint version
455+
# where the constraint comparator is for equality (any of "=", "<=", or ">=")
456+
# then the "tested version" is in the range. Check is finished.
457+
for constraint in constraints:
458+
if "=" in constraint.comparator and version == constraint.version:
459+
return True
460+
461461
# Split the constraint list in two sub lists:
462462
# a first list where the comparator is "=" or "!="
463463
# a second list where the comparator is neither "=" nor "!="
@@ -487,13 +487,9 @@ def contains_version(version, constraints):
487487
# and the "tested version" is greater than the current version
488488
# and the "tested version" is less than the next version
489489
# then the "tested version" is IN the range. Check is finished.
490-
if (
491-
cur_comp in (">", ">=")
492-
and nxt_comp in ("<", "<=")
493-
and version > cur_constraint.version
494-
and version < nxt_constraint.version
495-
):
496-
return True
490+
if cur_comp in (">", ">=") and nxt_comp in ("<", "<="):
491+
if version > cur_constraint.version and version < nxt_constraint.version:
492+
return True
497493

498494
# If current comparator is "<" or <=" and next comparator is ">" or >="
499495
# then these versions are out the range. Continue to the next iteration.

0 commit comments

Comments
 (0)