File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -169,7 +169,7 @@ impl HumanReadableName {
169169		if  user. is_empty ( )  || domain. is_empty ( )  { 
170170			return  Err ( ( ) ) ; 
171171		} 
172- 		if  !user . is_ascii ( )  || !domain . is_ascii ( )  { 
172+ 		if  !Hostname :: str_is_valid_hostname ( & user )  || !Hostname :: str_is_valid_hostname ( & domain )  { 
173173			return  Err ( ( ) ) ; 
174174		} 
175175		Ok ( HumanReadableName  {  user,  domain } ) 
Original file line number Diff line number Diff line change @@ -1490,6 +1490,16 @@ impl Hostname {
14901490 	pub  fn  len ( & self )  -> u8  { 
14911491		( & self . 0 ) . len ( )  as  u8 
14921492	} 
1493+ 
1494+ 	/// Check if the chars in `s` are allowed to be included in a [`Hostname`]. 
1495+  	pub ( crate )  fn  str_is_valid_hostname ( s :  & str )  -> bool  { 
1496+ 		s. len ( )  <= 255  &&
1497+ 		s. chars ( ) . all ( |c|
1498+ 			c. is_ascii_alphanumeric ( )  ||
1499+ 			c == '.'  ||
1500+ 			c == '-' 
1501+ 		) 
1502+ 	} 
14931503} 
14941504
14951505impl  core:: fmt:: Display  for  Hostname  { 
@@ -1525,11 +1535,7 @@ impl TryFrom<String> for Hostname {
15251535	type  Error  = ( ) ; 
15261536
15271537	fn  try_from ( s :  String )  -> Result < Self ,  Self :: Error >  { 
1528- 		if  s. len ( )  <= 255  && s. chars ( ) . all ( |c|
1529- 			c. is_ascii_alphanumeric ( )  ||
1530- 			c == '.'  ||
1531- 			c == '-' 
1532- 		)  { 
1538+ 		if  Hostname :: str_is_valid_hostname ( & s)  { 
15331539			Ok ( Hostname ( s) ) 
15341540		}  else  { 
15351541			Err ( ( ) ) 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments