@@ -480,7 +480,7 @@ def from_native(cls, string):
480480 return cls (constraints = constraints )
481481
482482
483- def split_req (string , comparators , comparators_rear = {}, default = None , strip = "" ):
483+ def split_req (string , comparators , default = None , strip = "" ):
484484 """
485485 Return a tuple of (vers comparator, version) strings given an common version
486486 requirement``string`` such as "> 2.3" or "<= 2.3" using the ``comparators``
@@ -501,8 +501,6 @@ def split_req(string, comparators, comparators_rear={}, default=None, strip=""):
501501 >>> assert split_req(">= 2.3", comparators=comps) == (">=", "2.3",)
502502 >>> assert split_req("<= 2.3", comparators=comps) == ("<=", "2.3",)
503503 >>> assert split_req("(< = 2.3 )", comparators=comps, strip=")(") == ("<=", "2.3",)
504- >>> comps_rear = {")": "<", "]": "<="}
505- >>> assert split_req(" 2.3 ]", comparators=comps, comparators_rear=comps_rear) == ("<=", "2.3",)
506504
507505 With a default, we return the default comparator::
508506
@@ -523,12 +521,6 @@ def split_req(string, comparators, comparators_rear={}, default=None, strip=""):
523521 version = constraint_string .lstrip (native_comparator )
524522 return vers_comparator , version
525523
526- # Some bracket notation comparators starts from end.
527- for native_comparator , vers_comparator in comparators_rear .items ():
528- if constraint_string .endswith (native_comparator ):
529- version = constraint_string .rstrip (native_comparator )
530- return vers_comparator , version
531-
532524 if default :
533525 return default , constraint_string
534526
@@ -1300,14 +1292,35 @@ def build_range_from_github_advisory_constraint(scheme: str, string: Union[str,
13001292 ">=" : ">=" ,
13011293 "<" : "<" ,
13021294 ">" : ">" ,
1303- "(" : ">" ,
1304- "[" : ">=" ,
13051295}
13061296
1307- vers_by_snyk_native_comparators_rear = {
1308- ")" : "<" ,
1309- "]" : "<=" ,
1310- }
1297+
1298+ def split_req_bracket_notation (string ):
1299+ """
1300+ Return a tuple of (vers comparator, version) strings given an bracket notation
1301+ version requirement ``string`` such as "(2.3" or "3.9]"
1302+
1303+ For example::
1304+
1305+ >>> assert split_req_bracket_notation(" 2.3 ]") == ("<=", "2.3")
1306+ >>> assert split_req_bracket_notation("( 3.9") == (">", "3.9")
1307+ """
1308+ comparators_front = {"(" : ">" , "[" : ">=" }
1309+ comparators_rear = {")" : "<" , "]" : "<=" }
1310+
1311+ constraint_string = remove_spaces (string ).strip ()
1312+
1313+ for native_comparator , vers_comparator in comparators_front .items ():
1314+ if constraint_string .startswith (native_comparator ):
1315+ version = constraint_string .lstrip (native_comparator )
1316+ return vers_comparator , version
1317+
1318+ for native_comparator , vers_comparator in comparators_rear .items ():
1319+ if constraint_string .endswith (native_comparator ):
1320+ version = constraint_string .rstrip (native_comparator )
1321+ return vers_comparator , version
1322+
1323+ raise ValueError (f"Unknown comparator in version requirement: { string !r} " )
13111324
13121325
13131326def build_range_from_snyk_advisory_string (scheme : str , string : Union [str , List ]):
@@ -1346,11 +1359,13 @@ def build_range_from_snyk_advisory_string(scheme: str, string: Union[str, List])
13461359 constraints = snyk_constraints .split (" " )
13471360
13481361 for constraint in constraints :
1349- comparator , version = split_req (
1350- string = constraint ,
1351- comparators = vers_by_snyk_native_comparators ,
1352- comparators_rear = vers_by_snyk_native_comparators_rear ,
1353- )
1362+ if any (comp in constraint for comp in "[]()" ):
1363+ comparator , version = split_req_bracket_notation (string = constraint )
1364+ else :
1365+ comparator , version = split_req (
1366+ string = constraint ,
1367+ comparators = vers_by_snyk_native_comparators ,
1368+ )
13541369 if comparator and version :
13551370 version = vrc .version_class (version )
13561371 version_constraints .append (
@@ -1382,10 +1397,7 @@ def build_range_from_discrete_version_string(scheme: str, string: Union[str, Lis
13821397 string = [string ]
13831398
13841399 for item in string :
1385- version = item .strip ().lstrip ("vV" )
1386- if version == "0" :
1387- continue
1388-
1400+ version = item .strip ()
13891401 version = vrc .version_class (version )
13901402 version_constraints .append (
13911403 VersionConstraint (
0 commit comments