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 ! (
@@ -210,6 +219,13 @@ impl<'de> serde::Deserialize<'de> for PartialVersion {
210
219
}
211
220
}
212
221
222
+ fn is_req ( value : & str ) -> bool {
223
+ let Some ( first) = value. chars ( ) . next ( ) else {
224
+ return false ;
225
+ } ;
226
+ "<>=^~" . contains ( first) || value. contains ( '*' ) || value. contains ( ',' )
227
+ }
228
+
213
229
#[ cfg( test) ]
214
230
mod tests {
215
231
use super :: * ;
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ Caused by:
52
52
|
53
53
6 | rust-version = \" ^1.43\"
54
54
| ^^^^^^^
55
- expected a version like \" 1.32\" " ,
55
+ unexpected version requirement, expected a version like \" 1.32\" " ,
56
56
)
57
57
. run ( ) ;
58
58
}
@@ -85,7 +85,7 @@ Caused by:
85
85
|
86
86
6 | rust-version = \" 1.43-beta.1\"
87
87
| ^^^^^^^^^^^^^
88
- expected a version like \" 1.32\" " ,
88
+ unexpected prerelease field, expected a version like \" 1.32\" " ,
89
89
)
90
90
. run ( ) ;
91
91
}
You can’t perform that action at this time.
0 commit comments