Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions data-url/tests/wpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn run_data_url(
if let Some(expected_mime) = expected_mime {
let url = url.unwrap();
let (body, _) = url.decode_to_vec().unwrap();
if expected_mime == "" {
if expected_mime.is_empty() {
assert_eq!(url.mime_type().to_string(), "text/plain;charset=US-ASCII")
} else {
assert_eq!(url.mime_type().to_string(), expected_mime)
Expand All @@ -41,7 +41,7 @@ where
enum TestCase {
Two(String, Option<String>),
Three(String, Option<String>, Vec<u8>),
};
}

let v: Vec<TestCase> = serde_json::from_str(include_str!("data-urls.json")).unwrap();
for test in v {
Expand Down
2 changes: 1 addition & 1 deletion idna/tests/uts46.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use idna::Errors;
pub fn collect_tests<F: FnMut(String, TestFn)>(add_test: &mut F) {
// https://www.unicode.org/Public/idna/13.0.0/IdnaTestV2.txt
for (i, line) in include_str!("IdnaTestV2.txt").lines().enumerate() {
if line == "" || line.starts_with('#') {
if line.is_empty() || line.starts_with('#') {
continue;
}

Expand Down
12 changes: 6 additions & 6 deletions url/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,11 @@ fn parse_ipv4number(mut input: &str) -> Result<Option<u32>, ()> {
// So instead we check if the input looks like a real number and only return
// an error when it's an overflow.
let valid_number = match r {
8 => input.chars().all(|c| c >= '0' && c <= '7'),
10 => input.chars().all(|c| c >= '0' && c <= '9'),
16 => input
.chars()
.all(|c| (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')),
8 => input.chars().all(|c| ('0'..='7').contains(&c)),
10 => input.chars().all(|c| ('0'..='9').contains(&c)),
16 => input.chars().all(|c| {
('0'..='9').contains(&c) || ('a'..='f').contains(&c) || ('A'..='F').contains(&c)
}),
_ => false,
};

Expand Down Expand Up @@ -302,7 +302,7 @@ fn parse_ipv4addr(input: &str) -> ParseResult<Option<Ipv4Addr>> {
let mut numbers: Vec<u32> = Vec::new();
let mut overflow = false;
for part in parts {
if part == "" {
if part.is_empty() {
return Ok(None);
}
match parse_ipv4number(part) {
Expand Down
11 changes: 10 additions & 1 deletion url/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,7 @@ impl Url {
/// Return an object with methods to manipulate this URL’s path segments.
///
/// Return `Err(())` if this URL is cannot-be-a-base.
#[allow(clippy::clippy::result_unit_err)]
pub fn path_segments_mut(&mut self) -> Result<PathSegmentsMut<'_>, ()> {
if self.cannot_be_a_base() {
Err(())
Expand Down Expand Up @@ -1516,6 +1517,7 @@ impl Url {
/// # }
/// # run().unwrap();
/// ```
#[allow(clippy::clippy::result_unit_err)]
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" {
Expand Down Expand Up @@ -1655,7 +1657,7 @@ impl Url {
}

if let Some(host) = host {
if host == "" && SchemeType::from(self.scheme()).is_special() {
if host.is_empty() && SchemeType::from(self.scheme()).is_special() {
return Err(ParseError::EmptyHost);
}
let mut host_substr = host;
Expand Down Expand Up @@ -1786,6 +1788,7 @@ impl Url {
/// # run().unwrap();
/// ```
///
#[allow(clippy::clippy::result_unit_err)]
pub fn set_ip_host(&mut self, address: IpAddr) -> Result<(), ()> {
if self.cannot_be_a_base() {
return Err(());
Expand Down Expand Up @@ -1825,6 +1828,7 @@ impl Url {
/// # }
/// # run().unwrap();
/// ```
#[allow(clippy::clippy::result_unit_err)]
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" {
Expand Down Expand Up @@ -1917,6 +1921,7 @@ impl Url {
/// # }
/// # run().unwrap();
/// ```
#[allow(clippy::clippy::result_unit_err)]
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" {
Expand Down Expand Up @@ -2078,6 +2083,7 @@ impl Url {
/// # }
/// # run().unwrap();
/// ```
#[allow(clippy::clippy::result_unit_err)]
pub fn set_scheme(&mut self, scheme: &str) -> Result<(), ()> {
let mut parser = Parser::for_setter(String::new());
let remaining = parser.parse_scheme(parser::Input::new(scheme))?;
Expand Down Expand Up @@ -2157,6 +2163,7 @@ impl Url {
/// # }
/// ```
#[cfg(any(unix, windows, target_os = "redox"))]
#[allow(clippy::clippy::result_unit_err)]
pub fn from_file_path<P: AsRef<Path>>(path: P) -> Result<Url, ()> {
let mut serialization = "file://".to_owned();
let host_start = serialization.len() as u32;
Expand Down Expand Up @@ -2193,6 +2200,7 @@ impl Url {
/// Note that `std::path` does not consider trailing slashes significant
/// and usually does not include them (e.g. in `Path::parent()`).
#[cfg(any(unix, windows, target_os = "redox"))]
#[allow(clippy::clippy::result_unit_err)]
pub fn from_directory_path<P: AsRef<Path>>(path: P) -> Result<Url, ()> {
let mut url = Url::from_file_path(path)?;
if !url.serialization.ends_with('/') {
Expand Down Expand Up @@ -2309,6 +2317,7 @@ impl Url {
/// for a Windows path, is not UTF-8.)
#[inline]
#[cfg(any(unix, windows, target_os = "redox"))]
#[allow(clippy::clippy::result_unit_err)]
pub fn to_file_path(&self) -> Result<PathBuf, ()> {
if let Some(segments) = self.path_segments() {
let host = match self.host() {
Expand Down
10 changes: 5 additions & 5 deletions url/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,17 +295,17 @@ impl<'i> Input<'i> {
}

pub trait Pattern {
fn split_prefix<'i>(self, input: &mut Input<'i>) -> bool;
fn split_prefix(self, input: &mut Input) -> bool;
}

impl Pattern for char {
fn split_prefix<'i>(self, input: &mut Input<'i>) -> bool {
fn split_prefix(self, input: &mut Input) -> bool {
input.next() == Some(self)
}
}

impl<'a> Pattern for &'a str {
fn split_prefix<'i>(self, input: &mut Input<'i>) -> bool {
fn split_prefix(self, input: &mut Input) -> bool {
for c in self.chars() {
if input.next() != Some(c) {
return false;
Expand All @@ -316,7 +316,7 @@ impl<'a> Pattern for &'a str {
}

impl<F: FnMut(char) -> bool> Pattern for F {
fn split_prefix<'i>(self, input: &mut Input<'i>) -> bool {
fn split_prefix(self, input: &mut Input) -> bool {
input.next().map_or(false, self)
}
}
Expand Down Expand Up @@ -1071,7 +1071,7 @@ impl<'a> Parser<'a> {
Ok((has_host, host, remaining))
}

pub fn file_host<'i>(input: Input<'i>) -> ParseResult<(bool, String, Input<'i>)> {
pub fn file_host(input: Input) -> ParseResult<(bool, String, Input)> {
// Undo the Input abstraction here to avoid allocating in the common case
// where the host part of the input does not contain any tab or newline
let input_str = input.chars.as_str();
Expand Down
6 changes: 6 additions & 0 deletions url/src/quirks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub fn protocol(url: &Url) -> &str {
}

/// Setter for https://url.spec.whatwg.org/#dom-url-protocol
#[allow(clippy::clippy::result_unit_err)]
pub fn set_protocol(url: &mut Url, mut new_protocol: &str) -> Result<(), ()> {
// The scheme state in the spec ignores everything after the first `:`,
// but `set_scheme` errors if there is more.
Expand All @@ -72,6 +73,7 @@ pub fn username(url: &Url) -> &str {
}

/// Setter for https://url.spec.whatwg.org/#dom-url-username
#[allow(clippy::clippy::result_unit_err)]
pub fn set_username(url: &mut Url, new_username: &str) -> Result<(), ()> {
url.set_username(new_username)
}
Expand All @@ -83,6 +85,7 @@ pub fn password(url: &Url) -> &str {
}

/// Setter for https://url.spec.whatwg.org/#dom-url-password
#[allow(clippy::clippy::result_unit_err)]
pub fn set_password(url: &mut Url, new_password: &str) -> Result<(), ()> {
url.set_password(if new_password.is_empty() {
None
Expand All @@ -98,6 +101,7 @@ pub fn host(url: &Url) -> &str {
}

/// Setter for https://url.spec.whatwg.org/#dom-url-host
#[allow(clippy::clippy::result_unit_err)]
pub fn set_host(url: &mut Url, new_host: &str) -> Result<(), ()> {
// If context object’s url’s cannot-be-a-base-URL flag is set, then return.
if url.cannot_be_a_base() {
Expand Down Expand Up @@ -154,6 +158,7 @@ pub fn hostname(url: &Url) -> &str {
}

/// Setter for https://url.spec.whatwg.org/#dom-url-hostname
#[allow(clippy::clippy::result_unit_err)]
pub fn set_hostname(url: &mut Url, new_hostname: &str) -> Result<(), ()> {
if url.cannot_be_a_base() {
return Err(());
Expand Down Expand Up @@ -195,6 +200,7 @@ pub fn port(url: &Url) -> &str {
}

/// Setter for https://url.spec.whatwg.org/#dom-url-port
#[allow(clippy::clippy::result_unit_err)]
pub fn set_port(url: &mut Url, new_port: &str) -> Result<(), ()> {
let result;
{
Expand Down