Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forbid unprefixed SHAs for toolchains #723

Merged
merged 1 commit into from
Mar 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/toolchain.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::prelude::*;
use crate::utils;
use regex::Regex;
use rustwide::Toolchain as RustwideToolchain;
use std::fmt;
use std::str::FromStr;
Expand Down Expand Up @@ -102,6 +103,12 @@ pub enum ToolchainParseError {
InvalidSourceName(String),
#[error("invalid toolchain flag: {0}")]
InvalidFlag(String),
#[error("invalid toolchain SHA: {0} is missing a `try#` or `master#` prefix")]
PrefixMissing(String),
}

lazy_static! {
static ref TOOLCHAIN_SHA_RE: Regex = Regex::new(r"^[a-f0-9]{40}$").unwrap();
}

impl FromStr for Toolchain {
Expand Down Expand Up @@ -130,6 +137,10 @@ impl FromStr for Toolchain {
}
} else if raw_source.is_empty() {
return Err(ToolchainParseError::EmptyName);
} else if TOOLCHAIN_SHA_RE.is_match(raw_source) {
// A common user error is unprefixed SHAs for the `start` or `end` toolchains, check for
// these here.
return Err(ToolchainParseError::PrefixMissing(raw_source.to_string()));
} else {
RustwideToolchain::dist(raw_source)
};
Expand Down Expand Up @@ -348,5 +359,6 @@ mod tests {
assert!(Toolchain::from_str("stable+donotusethisflag=ever").is_err());
assert!(Toolchain::from_str("stable+patch=").is_err());
assert!(Toolchain::from_str("try#1234+target=").is_err());
assert!(Toolchain::from_str("0000000000000000000000000000000000000000").is_err());
}
}
Loading