File tree Expand file tree Collapse file tree 1 file changed +23
-5
lines changed Expand file tree Collapse file tree 1 file changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -105,12 +105,13 @@ pub async fn delete_version(
105105}
106106
107107async fn get_id ( conn : & mut sqlx:: PgConnection , name : & str ) -> Result < i32 > {
108- Ok (
109- sqlx:: query_scalar!( "SELECT id FROM crates WHERE name = $1" , name)
110- . fetch_optional ( & mut * conn)
111- . await ?
112- . ok_or_else ( || CrateDeletionError :: MissingCrate ( name. into ( ) ) ) ?,
108+ Ok ( sqlx:: query_scalar!(
109+ "SELECT id FROM crates WHERE normalize_crate_name(name) = normalize_crate_name($1)" ,
110+ name
113111 )
112+ . fetch_optional ( & mut * conn)
113+ . await ?
114+ . ok_or_else ( || CrateDeletionError :: MissingCrate ( name. into ( ) ) ) ?)
114115}
115116
116117// metaprogramming!
@@ -233,6 +234,23 @@ mod tests {
233234 . is_some ( ) )
234235 }
235236
237+ #[ test]
238+ fn test_get_id_uses_normalization ( ) {
239+ async_wrapper ( |env| async move {
240+ env. async_fake_release ( )
241+ . await
242+ . name ( "Some_Package" )
243+ . version ( "1.0.0" )
244+ . create_async ( )
245+ . await ?;
246+
247+ let mut conn = env. async_db ( ) . await . async_conn ( ) . await ;
248+ assert ! ( get_id( & mut conn, "some-package" ) . await . is_ok( ) ) ;
249+
250+ Ok ( ( ) )
251+ } )
252+ }
253+
236254 #[ test_case( true ) ]
237255 #[ test_case( false ) ]
238256 fn test_delete_crate ( archive_storage : bool ) {
You can’t perform that action at this time.
0 commit comments