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 {
169
169
if user. is_empty ( ) || domain. is_empty ( ) {
170
170
return Err ( ( ) ) ;
171
171
}
172
- if !user . is_ascii ( ) || !domain . is_ascii ( ) {
172
+ if !Hostname :: str_is_valid_hostname ( & user ) || !Hostname :: str_is_valid_hostname ( & domain ) {
173
173
return Err ( ( ) ) ;
174
174
}
175
175
Ok ( HumanReadableName { user, domain } )
Original file line number Diff line number Diff line change @@ -1490,6 +1490,16 @@ impl Hostname {
1490
1490
pub fn len ( & self ) -> u8 {
1491
1491
( & self . 0 ) . len ( ) as u8
1492
1492
}
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
+ }
1493
1503
}
1494
1504
1495
1505
impl core:: fmt:: Display for Hostname {
@@ -1525,11 +1535,7 @@ impl TryFrom<String> for Hostname {
1525
1535
type Error = ( ) ;
1526
1536
1527
1537
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) {
1533
1539
Ok ( Hostname ( s) )
1534
1540
} else {
1535
1541
Err ( ( ) )
You can’t perform that action at this time.
0 commit comments