File tree 2 files changed +18
-2
lines changed
2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -136,9 +136,18 @@ impl std::str::FromStr for PartialVersion {
136
136
// HACK: `PartialVersion` is a subset of the `VersionReq` syntax that only ever
137
137
// has one comparator with a required minor and optional patch, and uses no
138
138
// other features.
139
+ if is_req ( value) {
140
+ anyhow:: bail!( "unexpected version requirement, expected a version like \" 1.32\" " )
141
+ }
139
142
let version_req = match semver:: VersionReq :: parse ( value) {
140
143
// Exclude semver operators like `^` and pre-release identifiers
141
144
Ok ( req) if value. chars ( ) . all ( |c| c. is_ascii_digit ( ) || c == '.' ) => req,
145
+ Err ( _) if value. contains ( '+' ) => {
146
+ anyhow:: bail!( "unexpected build field, expected a version like \" 1.32\" " )
147
+ }
148
+ Err ( _) if value. contains ( '-' ) => {
149
+ anyhow:: bail!( "unexpected prerelease field, expected a version like \" 1.32\" " )
150
+ }
142
151
_ => anyhow:: bail!( "expected a version like \" 1.32\" " ) ,
143
152
} ;
144
153
assert_eq ! (
@@ -211,6 +220,13 @@ impl<'de> serde::Deserialize<'de> for PartialVersion {
211
220
}
212
221
}
213
222
223
+ fn is_req ( value : & str ) -> bool {
224
+ let Some ( first) = value. chars ( ) . next ( ) else {
225
+ return false ;
226
+ } ;
227
+ "<>=^~" . contains ( first) || value. contains ( '*' ) || value. contains ( ',' )
228
+ }
229
+
214
230
#[ cfg( test) ]
215
231
mod tests {
216
232
use super :: * ;
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ fn rust_version_bad_caret() {
48
48
error: failed to parse manifest at `[..]`
49
49
50
50
Caused by:
51
- expected a version like \" 1.32\"
51
+ unexpected version requirement, expected a version like \" 1.32\"
52
52
in `package.rust-version`" ,
53
53
)
54
54
. run ( ) ;
@@ -78,7 +78,7 @@ fn rust_version_bad_pre_release() {
78
78
error: failed to parse manifest at `[..]`
79
79
80
80
Caused by:
81
- expected a version like \" 1.32\"
81
+ unexpected prerelease field, expected a version like \" 1.32\"
82
82
in `package.rust-version`" ,
83
83
)
84
84
. run ( ) ;
You can’t perform that action at this time.
0 commit comments