@@ -45,6 +45,21 @@ struct AzureConfig {
4545 sastoken : String ,
4646}
4747
48+ // Sanitize Azure Blob Index tag key/value components.
49+ // Replace any non [A-Za-z0-9_.-] characters with '_'.
50+ fn sanitize_tag_component ( input : & str ) -> String {
51+ input
52+ . chars ( )
53+ . map ( |c| {
54+ if c. is_ascii_alphanumeric ( ) || c == '-' || c == '_' || c == '.' {
55+ c
56+ } else {
57+ '_'
58+ }
59+ } )
60+ . collect ( )
61+ }
62+
4863/// Get Azure credentials from config.toml
4964fn get_azure_credentials ( name : & str ) -> AzureConfig {
5065 let cfg_content = get_config_content ( ) ;
@@ -149,7 +164,16 @@ async fn write_file_to_blob(filename: String, data: Vec<u8>, cont_type: String,
149164 // Set owner tag if email is provided
150165 if let Some ( email) = owner_email {
151166 let mut tags = Tags :: new ( ) ;
152- tags. insert ( "owner" . to_string ( ) , email) ;
167+ let sanitized = sanitize_tag_component ( & email) ;
168+ if sanitized != email {
169+ debug_log ! (
170+ "Sanitized owner tag value from '{}' to '{}'" ,
171+ email, sanitized
172+ ) ;
173+ }
174+ // Ensure non-empty value
175+ let final_value = if sanitized. is_empty ( ) { "_" . to_string ( ) } else { sanitized } ;
176+ tags. insert ( "owner" . to_string ( ) , final_value) ;
153177 match blob_client. set_tags ( tags) . await {
154178 Ok ( _) => {
155179 debug_log ! ( "Owner tag set successfully" ) ;
@@ -341,10 +365,25 @@ async fn azure_set_filename_tags(
341365 let blob_client = ClientBuilder :: new ( storage_account, storage_credential)
342366 . blob_client ( storage_container, storage_blob) ;
343367 let mut tags = Tags :: new ( ) ;
344- // iterate and add tags, tags are in format "
345- for tag in user_tags {
346- let ( tag, value) = tag;
347- tags. insert ( tag, value) ;
368+ // Iterate and add tags after sanitizing key and value
369+ for ( key, value) in user_tags {
370+ let sanitized_key = sanitize_tag_component ( & key) ;
371+ let sanitized_value = sanitize_tag_component ( & value) ;
372+ if sanitized_key != key || sanitized_value != value {
373+ debug_log ! (
374+ "Sanitized tag '{}'='{}' -> '{}'='{}'" ,
375+ key,
376+ value,
377+ sanitized_key,
378+ sanitized_value
379+ ) ;
380+ }
381+ if sanitized_key. is_empty ( ) {
382+ debug_log ! ( "Skipping tag with empty key after sanitization: '{}'" , key) ;
383+ continue ;
384+ }
385+ let final_value = if sanitized_value. is_empty ( ) { "_" . to_string ( ) } else { sanitized_value } ;
386+ tags. insert ( sanitized_key, final_value) ;
348387 }
349388 let res = blob_client. set_tags ( tags) . await ;
350389 match res {
0 commit comments