@@ -105,6 +105,8 @@ pub enum ToolchainParseError {
105
105
InvalidFlag ( String ) ,
106
106
#[ error( "invalid toolchain SHA: {0} is missing a `try#` or `master#` prefix" ) ]
107
107
PrefixMissing ( String ) ,
108
+ #[ error( "invalid url {0:?}: {1}" ) ]
109
+ InvalidUrl ( String , url:: ParseError ) ,
108
110
}
109
111
110
112
lazy_static ! {
@@ -187,7 +189,9 @@ impl FromStr for Toolchain {
187
189
#[ derive( Serialize , Deserialize , PartialEq , Eq , Hash , Debug , Clone ) ]
188
190
pub struct CratePatch {
189
191
pub name : String ,
190
- pub repo : String ,
192
+ // cargo currently doesn't accept scp-style "URLs" rust-lang/crates#1851
193
+ // so ensure its a proper URL
194
+ pub repo : url:: Url ,
191
195
pub branch : String ,
192
196
}
193
197
@@ -202,7 +206,8 @@ impl FromStr for CratePatch {
202
206
} else {
203
207
Ok ( CratePatch {
204
208
name : params[ 0 ] . into ( ) ,
205
- repo : params[ 1 ] . into ( ) ,
209
+ repo : url:: Url :: parse ( params[ 1 ] )
210
+ . map_err ( |err| ToolchainParseError :: InvalidUrl ( params[ 1 ] . into ( ) , err) ) ?,
206
211
branch : params[ 2 ] . into ( ) ,
207
212
} )
208
213
}
@@ -291,7 +296,7 @@ mod tests {
291
296
ci_try: $ci_try,
292
297
patches: vec![ CratePatch {
293
298
name: "example" . to_string( ) ,
294
- repo: "https://git.example.com/some/repo" . to_string ( ) ,
299
+ repo: url :: Url :: parse ( "https://git.example.com/some/repo" ) . unwrap ( ) ,
295
300
branch: "master" . to_string( )
296
301
} ]
297
302
} ) ;
@@ -306,7 +311,7 @@ mod tests {
306
311
ci_try: $ci_try,
307
312
patches: vec![ CratePatch {
308
313
name: "example" . to_string( ) ,
309
- repo: "https://git.example.com/some/repo" . to_string ( ) ,
314
+ repo: url :: Url :: parse ( "https://git.example.com/some/repo" ) . unwrap ( ) ,
310
315
branch: "master" . to_string( )
311
316
} ]
312
317
} ) ;
@@ -358,6 +363,13 @@ mod tests {
358
363
assert ! ( Toolchain :: from_str( "stable+rustdocflags=" ) . is_err( ) ) ;
359
364
assert ! ( Toolchain :: from_str( "stable+donotusethisflag=ever" ) . is_err( ) ) ;
360
365
assert ! ( Toolchain :: from_str( "stable+patch=" ) . is_err( ) ) ;
366
+ assert ! ( matches!(
367
+ Toolchain :: from_str(
368
+ "[email protected] :rust-random/getrandom=backports/v0.2"
369
+ )
370
+ . unwrap_err( ) ,
371
+ super :: ToolchainParseError :: InvalidUrl ( ..)
372
+ ) ) ;
361
373
assert ! ( Toolchain :: from_str( "try#1234+target=" ) . is_err( ) ) ;
362
374
assert ! ( Toolchain :: from_str( "0000000000000000000000000000000000000000" ) . is_err( ) ) ;
363
375
}
0 commit comments