Skip to main content

Module normalize_version

Module normalize_version 

Source
Expand description

Version ranges of GitHub repository advisories are written by hand, so they come in many shapes: >= v1.19.0, All, 1.2.0 through 1.8.7, >= 2.1.0 < 2.2.7, <=4.1.135.Final, 1.20.1 and earlier, stable <= 2.8.13; beta <= 3.0.0.beta15, …

normalize_version_range rewrites the shapes whose meaning is clear into the syntax that semver::VersionReq accepts; single versions are read by lenient_semver. It works as a list of small rules that are applied from top to bottom; every rule is a function with an example in its comment. A shape no rule understands comes out still unparsable, so that the caller fails to parse it and warns about it.

Output format: one space between an operator and its version, , between the comparators of one requirement (AND) and || between alternatives (OR). A range that already parses is returned unchanged, except a list of upper bounds like < 1.8.4, < 1.9.1, which is read as release branches.

Functions§

bound_every_version
interval_to_requirement
normalize_version_range
Rewrites a hand-written version range into the syntax semver::VersionReq accepts. >= v1.19.0, < v1.19.6 -> >= 1.19.0, < 1.19.6 1.2.0 through 1.8.7 -> >= 1.2.0, <= 1.8.7 >= 2.1.0 < 2.2.7, >= 2.3.0 < 2.3.4 -> >= 2.1.0, < 2.2.7 || >= 2.3.0, < 2.3.4 < 1.8.4, < 1.9.1 -> >= 1.8.0, < 1.8.4 || >= 1.9.0, < 1.9.1 v1.18.0,v1.18.1 -> = 1.18.0 || = 1.18.1 All -> * >= 1.0.0, < 1.2.6 -> >= 1.0.0, < 1.2.6 (already valid: unchanged) NONE -> = NONE (still unparsable: the caller warns)