File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 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 {
136136 // HACK: `PartialVersion` is a subset of the `VersionReq` syntax that only ever
137137 // has one comparator with a required minor and optional patch, and uses no
138138 // other features.
139+ if is_req ( value) {
140+ anyhow:: bail!( "unexpected version requirement, expected a version like \" 1.32\" " )
141+ }
139142 let version_req = match semver:: VersionReq :: parse ( value) {
140143 // Exclude semver operators like `^` and pre-release identifiers
141144 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+ }
142151 _ => anyhow:: bail!( "expected a version like \" 1.32\" " ) ,
143152 } ;
144153 assert_eq ! (
@@ -211,6 +220,13 @@ impl<'de> serde::Deserialize<'de> for PartialVersion {
211220 }
212221}
213222
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+
214230#[ cfg( test) ]
215231mod tests {
216232 use super :: * ;
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ Caused by:
5252 |
5353 6 | rust-version = \" ^1.43\"
5454 | ^^^^^^^
55- expected a version like \" 1.32\" " ,
55+ unexpected version requirement, expected a version like \" 1.32\" " ,
5656 )
5757 . run ( ) ;
5858}
@@ -85,7 +85,7 @@ Caused by:
8585 |
8686 6 | rust-version = \" 1.43-beta.1\"
8787 | ^^^^^^^^^^^^^
88- expected a version like \" 1.32\" " ,
88+ unexpected prerelease field, expected a version like \" 1.32\" " ,
8989 )
9090 . run ( ) ;
9191}
You can’t perform that action at this time.
0 commit comments