File tree 1 file changed +12
-0
lines changed
1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 1
1
use crate :: prelude:: * ;
2
2
use crate :: utils;
3
+ use regex:: Regex ;
3
4
use rustwide:: Toolchain as RustwideToolchain ;
4
5
use std:: fmt;
5
6
use std:: str:: FromStr ;
@@ -102,6 +103,12 @@ pub enum ToolchainParseError {
102
103
InvalidSourceName ( String ) ,
103
104
#[ error( "invalid toolchain flag: {0}" ) ]
104
105
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( ) ;
105
112
}
106
113
107
114
impl FromStr for Toolchain {
@@ -130,6 +137,10 @@ impl FromStr for Toolchain {
130
137
}
131
138
} else if raw_source. is_empty ( ) {
132
139
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 ( ) ) ) ;
133
144
} else {
134
145
RustwideToolchain :: dist ( raw_source)
135
146
} ;
@@ -348,5 +359,6 @@ mod tests {
348
359
assert ! ( Toolchain :: from_str( "stable+donotusethisflag=ever" ) . is_err( ) ) ;
349
360
assert ! ( Toolchain :: from_str( "stable+patch=" ) . is_err( ) ) ;
350
361
assert ! ( Toolchain :: from_str( "try#1234+target=" ) . is_err( ) ) ;
362
+ assert ! ( Toolchain :: from_str( "0000000000000000000000000000000000000000" ) . is_err( ) ) ;
351
363
}
352
364
}
You can’t perform that action at this time.
0 commit comments