Skip to content

Commit 71e1581

Browse files
committed
fix(dist): throw an error when a PartialVersion string doesn't start with an ASCII digit
1 parent 605b3c4 commit 71e1581

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/dist/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,17 @@ impl fmt::Display for PartialVersion {
208208
impl FromStr for PartialVersion {
209209
type Err = anyhow::Error;
210210
fn from_str(ver: &str) -> Result<Self> {
211+
// `semver::Comparator::from_str` supports an optional operator
212+
// (e.g. `=`, `>`, `>=`, `<`, `<=`, `~`, `^`, `*`) before the
213+
// partial version, so we should exclude that case first.
214+
if let Some(ch) = ver.chars().nth(0) {
215+
if !ch.is_ascii_digit() {
216+
return Err(anyhow!(
217+
"expected ASCII digit at the beginning of `{ver}`, found `{ch}`"
218+
)
219+
.context("error parsing `PartialVersion`"));
220+
}
221+
}
211222
let (ver, pre) = ver.split_once('-').unwrap_or((ver, ""));
212223
let comparator =
213224
semver::Comparator::from_str(ver).context("error parsing `PartialVersion`")?;

0 commit comments

Comments
 (0)