Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add url.includes_credentials() and url.is_special(). #520

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/lib.rs
Expand Up @@ -1497,8 +1497,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 @@ -1807,8 +1806,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 @@ -1899,8 +1897,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 @@ -2361,6 +2358,12 @@ impl Url {

// Private helper methods:

fn cannot_have_username_password_port(&self) -> bool {
self.host().unwrap_or(Host::Domain("")) == Host::Domain("")
Copy link
Contributor

@djc djc Aug 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to link https://url.spec.whatwg.org/#url-miscellaneous in a comment here.

|| self.cannot_be_a_base()
|| self.scheme() == "file"
}

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