Skip to content

Commit f2a10b4

Browse files
committed
Auto merge of #723 - lqd:unprefixed-shas, r=Mark-Simulacrum
Forbid unprefixed SHAs for toolchains This PR forbids unprefixed SHAs for toolchain arguments, to avoid crater hanging when they appear. I'm not sure this is fully valid though: I don't know if SHAs could appear in a `Toolchain`'s name (and `RustwideToolchain::dist()`) without being an error 😓. This commonly happens with `rustup-toolchain-install-master` but I don't know if a similar situation could arise within common crater usage. CI will surely fail: some of the used dependencies are broken on nightly right now, and clippy emits warnings -- both issues are fixed in #722. <sub>(this is [for](rust-lang/rust#122230 (comment)) `@oli-obk` and [for](rust-lang/rust#122502 (comment)) `@compiler-errors)</sub>`
2 parents f2ebb4c + aedec6d commit f2a10b4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/toolchain.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::prelude::*;
22
use crate::utils;
3+
use regex::Regex;
34
use rustwide::Toolchain as RustwideToolchain;
45
use std::fmt;
56
use std::str::FromStr;
@@ -102,6 +103,12 @@ pub enum ToolchainParseError {
102103
InvalidSourceName(String),
103104
#[error("invalid toolchain flag: {0}")]
104105
InvalidFlag(String),
106+
#[error("invalid toolchain SHA: {0} is missing a `try#` or `master#` prefix")]
107+
PrefixMissing(String),
108+
}
109+
110+
lazy_static! {
111+
static ref TOOLCHAIN_SHA_RE: Regex = Regex::new(r"^[a-f0-9]{40}$").unwrap();
105112
}
106113

107114
impl FromStr for Toolchain {
@@ -130,6 +137,10 @@ impl FromStr for Toolchain {
130137
}
131138
} else if raw_source.is_empty() {
132139
return Err(ToolchainParseError::EmptyName);
140+
} else if TOOLCHAIN_SHA_RE.is_match(raw_source) {
141+
// A common user error is unprefixed SHAs for the `start` or `end` toolchains, check for
142+
// these here.
143+
return Err(ToolchainParseError::PrefixMissing(raw_source.to_string()));
133144
} else {
134145
RustwideToolchain::dist(raw_source)
135146
};
@@ -348,5 +359,6 @@ mod tests {
348359
assert!(Toolchain::from_str("stable+donotusethisflag=ever").is_err());
349360
assert!(Toolchain::from_str("stable+patch=").is_err());
350361
assert!(Toolchain::from_str("try#1234+target=").is_err());
362+
assert!(Toolchain::from_str("0000000000000000000000000000000000000000").is_err());
351363
}
352364
}

0 commit comments

Comments
 (0)