@@ -256,6 +256,24 @@ fn generate_guid(key: &[u8]) -> Uuid {
256256 Uuid :: new_v5 ( & namespace, key)
257257}
258258
259+ fn wix_identifier ( id : & str ) -> String {
260+ let mut identifier: String = id
261+ . replace ( '-' , "_" )
262+ . chars ( )
263+ . filter ( |c| c. is_ascii_alphanumeric ( ) || * c == '_' || * c == '.' )
264+ . collect ( ) ;
265+
266+ if !identifier
267+ . chars ( )
268+ . next ( )
269+ . is_some_and ( |c| c. is_ascii_alphabetic ( ) || c == '_' )
270+ {
271+ identifier. insert ( 0 , '_' ) ;
272+ }
273+
274+ identifier
275+ }
276+
259277// Specifically goes and gets Wix and verifies the download via Sha256
260278pub fn get_and_extract_wix ( path : & Path ) -> crate :: Result < ( ) > {
261279 log:: info!( "Verifying wix package" ) ;
@@ -899,7 +917,6 @@ fn generate_binaries_data(settings: &Settings) -> crate::Result<Vec<Binary>> {
899917 let mut binaries = Vec :: new ( ) ;
900918 let cwd = std:: env:: current_dir ( ) ?;
901919 let tmp_dir = std:: env:: temp_dir ( ) ;
902- let regex = Regex :: new ( r"[^\w\d\.]" ) ?;
903920 for src in settings. external_binaries ( ) {
904921 let src = src?;
905922 let binary_path = cwd. join ( & src) ;
@@ -917,9 +934,7 @@ fn generate_binaries_data(settings: &Settings) -> crate::Result<Vec<Binary>> {
917934 . into_os_string ( )
918935 . into_string ( )
919936 . expect ( "failed to read external binary path" ) ,
920- id : regex
921- . replace_all ( & dest_filename. replace ( '-' , "_" ) , "" )
922- . to_string ( ) ,
937+ id : wix_identifier ( & dest_filename) ,
923938 } ) ;
924939 }
925940
@@ -932,9 +947,7 @@ fn generate_binaries_data(settings: &Settings) -> crate::Result<Vec<Binary>> {
932947 . into_os_string ( )
933948 . into_string ( )
934949 . expect ( "failed to read binary path" ) ,
935- id : regex
936- . replace_all ( & bin. name ( ) . replace ( '-' , "_" ) , "" )
937- . to_string ( ) ,
950+ id : wix_identifier ( bin. name ( ) ) ,
938951 } )
939952 }
940953 }
@@ -1153,4 +1166,14 @@ mod tests {
11531166 assert ! ( convert_version( "1.1.2-alpha.4" ) . is_err( ) ) ;
11541167 assert ! ( convert_version( "1.1.2+asd.3" ) . is_err( ) ) ;
11551168 }
1169+
1170+ #[ test]
1171+ fn sanitizes_wix_identifiers ( ) {
1172+ assert_eq ! ( wix_identifier( "7za.exe" ) , "_7za.exe" ) ;
1173+ assert_eq ! ( wix_identifier( "my-app.exe" ) , "my_app.exe" ) ;
1174+ assert_eq ! ( wix_identifier( "bad name!.exe" ) , "badname.exe" ) ;
1175+ assert_eq ! ( wix_identifier( ".bin" ) , "_.bin" ) ;
1176+ assert_eq ! ( wix_identifier( "" ) , "_" ) ;
1177+ assert_eq ! ( wix_identifier( "app_1.2" ) , "app_1.2" ) ;
1178+ }
11561179}
0 commit comments