Skip to content

Commit

Permalink
Add cannot_have_username_password_port to URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
o0Ignition0o committed Jul 19, 2019
1 parent 5d79947 commit 5885c84
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/lib.rs
Expand Up @@ -1428,8 +1428,7 @@ impl Url {
/// # run().unwrap();
/// ```
pub fn set_port(&mut self, mut port: Option<u16>) -> Result<(), ()> {
// has_host implies !cannot_be_a_base
if !self.has_host() || self.host() == Some(Host::Domain("")) || self.scheme() == "file" {
if self.cannot_have_username_password_port() {
return Err(());
}
if port.is_some() && port == parser::default_port(self.scheme()) {
Expand Down Expand Up @@ -1719,8 +1718,7 @@ impl Url {
/// # run().unwrap();
/// ```
pub fn set_password(&mut self, password: Option<&str>) -> Result<(), ()> {
// has_host implies !cannot_be_a_base
if !self.has_host() || self.host() == Some(Host::Domain("")) || self.scheme() == "file" {
if self.cannot_have_username_password_port() {
return Err(());
}
if let Some(password) = password {
Expand Down Expand Up @@ -1811,8 +1809,7 @@ impl Url {
/// # run().unwrap();
/// ```
pub fn set_username(&mut self, username: &str) -> Result<(), ()> {
// has_host implies !cannot_be_a_base
if !self.has_host() || self.host() == Some(Host::Domain("")) || self.scheme() == "file" {
if self.cannot_have_username_password_port() {
return Err(());
}
let username_start = self.scheme_end + 3;
Expand Down Expand Up @@ -2210,6 +2207,12 @@ impl Url {

// Private helper methods:

fn cannot_have_username_password_port(&self) -> bool {
self.host().unwrap_or(Host::Domain("")) == Host::Domain("")
|| self.cannot_be_a_base()
|| self.scheme() == "file"
}

#[inline]
fn slice<R>(&self, range: R) -> &str
where
Expand Down

0 comments on commit 5885c84

Please sign in to comment.