Skip to content

Commit

Permalink
Resort to strict version matching for invalid PackageVersionConstraint
Browse files Browse the repository at this point in the history
If there isn't a constraint (only `=` is currently supported) and the
version cannot be parsed as a SemVer (`VersionReq`), we'll automatically
fall back to strict version matching (as if `=` was provided) in order
to better support exotic versions. This is done to retain CLI
compatibility with the old behaviour.

Signed-off-by: Michael Weiss <[email protected]>
  • Loading branch information
primeos-work committed Jan 9, 2025
1 parent b2388c5 commit 9296e91
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/package/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use pom::parser::Parser as PomParser;
use regex::Regex;
use serde::Deserialize;
use serde::Serialize;
use tracing::info;

use crate::util::parser::*;

Expand Down Expand Up @@ -47,8 +48,15 @@ impl PackageVersionConstraint {
.map_err(Error::from)
} else {
semver::VersionReq::parse(&(Self::get_default_constraint() + &version))
.map(|_| ("".to_string(), version))
.map(|_| ("".to_string(), version.clone()))
.map_err(Error::from)
// TODO: Drop this (for backward compatibility, we temporarily fallback to
// the old behaviour (as if the constraint `=` was specified) if the
// provided version cannot be parsed by the semver crate - this is required
// for somewhat "exotic" versions like the old OpenSSL 1.1.1w, web browsers
// with a fourth version number, or (unstable) releases based on the date):
.inspect_err(|e| info!("Couldn't parse version \"{version}\" as SemVer ({e}) -> falling back to strict version matching (={version})"))
.map_or(Ok(("=".to_string(), version)), |x| Ok(x))
}
})
.map(|(constraint, version)| PackageVersionConstraint {
Expand Down

0 comments on commit 9296e91

Please sign in to comment.