Skip to content

Commit f55449c

Browse files
AnotherDanielsophokles73
authored andcommitted
Add remote authority check
1 parent 66830f3 commit f55449c

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

src/uri.rs

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,8 @@ impl UUri {
553553
self.eq(&UUri::default())
554554
}
555555

556-
/// Check if an `UUri` is remote, by comparing authority fields. UUris with empty authority are
557-
/// considered to be local.
556+
/// Check if an `UUri` is remote, by comparing authority fields.
557+
/// UUris with empty authority are considered to be local.
558558
///
559559
/// # Returns
560560
///
@@ -568,21 +568,49 @@ impl UUri {
568568
///
569569
/// let authority_a = UUri::from_str("up://Authority.A/100A/1/0").unwrap();
570570
/// let authority_b = UUri::from_str("up://Authority.B/200B/2/20").unwrap();
571-
/// assert!(authority_a.is_remote_authority(&authority_b));
571+
/// assert!(authority_a.is_remote(&authority_b));
572572
///
573573
/// let authority_local = UUri::from_str("up:///100A/1/0").unwrap();
574-
/// assert!(!authority_local.is_remote_authority(&authority_a));
574+
/// assert!(!authority_local.is_remote(&authority_a));
575575
///
576576
/// let authority_wildcard = UUri::from_str("up://*/100A/1/0").unwrap();
577-
/// assert!(!authority_wildcard.is_remote_authority(&authority_a));
578-
/// assert!(!authority_a.is_remote_authority(&authority_wildcard));
579-
/// assert!(!authority_wildcard.is_remote_authority(&authority_wildcard));
577+
/// assert!(!authority_wildcard.is_remote(&authority_a));
578+
/// assert!(!authority_a.is_remote(&authority_wildcard));
579+
/// assert!(!authority_wildcard.is_remote(&authority_wildcard));
580580
/// ````
581-
pub fn is_remote_authority(&self, other_uri: &UUri) -> bool {
582-
!self.authority_name.is_empty()
583-
&& self.authority_name != WILDCARD_AUTHORITY
584-
&& other_uri.authority_name != WILDCARD_AUTHORITY
585-
&& self.authority_name != other_uri.authority_name
581+
pub fn is_remote(&self, other_uri: &UUri) -> bool {
582+
self.is_remote_authority(&other_uri.authority_name)
583+
}
584+
585+
/// Check if an authority is remote compared to the authority field of the UUri.
586+
/// Empty authorities are considered to be local.
587+
///
588+
/// # Returns
589+
///
590+
/// 'true' if authority is a different than `Self.authority_name`, `false` otherwise.
591+
///
592+
/// # Examples
593+
///
594+
/// ```rust
595+
/// use std::str::FromStr;
596+
/// use up_rust::UUri;
597+
///
598+
/// let authority_a = UUri::from_str("up://Authority.A/100A/1/0").unwrap();
599+
/// let authority_b = "Authority.B".to_string();
600+
/// assert!(authority_a.is_remote_authority(&authority_b));
601+
///
602+
/// let authority_local = "".to_string();
603+
/// assert!(!authority_a.is_remote_authority(&authority_local));
604+
///
605+
/// let authority_wildcard = "*".to_string();
606+
/// assert!(!authority_a.is_remote_authority(&authority_wildcard));
607+
/// ```
608+
pub fn is_remote_authority(&self, authority: &String) -> bool {
609+
!authority.is_empty()
610+
&& !self.authority_name.is_empty()
611+
&& !self.has_wildcard_authority()
612+
&& authority != WILDCARD_AUTHORITY
613+
&& self.authority_name != *authority
586614
}
587615

588616
/// Checks if this UUri has an empty authority name.

0 commit comments

Comments
 (0)