mirror of
				https://github.com/kata-containers/kata-containers.git
				synced 2025-11-04 03:29:55 +00:00 
			
		
		
		
	agent: Remove unwrap from verify_cid()
Improved the `verify_cid()` function that validates container ID's by removing the need for an `unwrap()`. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
		@@ -111,11 +111,18 @@ pub struct AgentService {
 | 
				
			|||||||
//     ^[a-zA-Z0-9][a-zA-Z0-9_.-]+$
 | 
					//     ^[a-zA-Z0-9][a-zA-Z0-9_.-]+$
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
fn verify_cid(id: &str) -> Result<()> {
 | 
					fn verify_cid(id: &str) -> Result<()> {
 | 
				
			||||||
    let valid = id.len() > 1
 | 
					    let mut chars = id.chars();
 | 
				
			||||||
        && id.chars().next().unwrap().is_alphanumeric()
 | 
					
 | 
				
			||||||
        && id
 | 
					    let valid = match chars.next() {
 | 
				
			||||||
            .chars()
 | 
					        Some(first)
 | 
				
			||||||
            .all(|c| (c.is_alphanumeric() || ['.', '-', '_'].contains(&c)));
 | 
					            if first.is_alphanumeric()
 | 
				
			||||||
 | 
					                && id.len() > 1
 | 
				
			||||||
 | 
					                && chars.all(|c| c.is_alphanumeric() || ['.', '-', '_'].contains(&c)) =>
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            true
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        _ => false,
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    match valid {
 | 
					    match valid {
 | 
				
			||||||
        true => Ok(()),
 | 
					        true => Ok(()),
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user