Skip to content

Commit

Permalink
Merge pull request #790 from crowlKats/remove_idna
Browse files Browse the repository at this point in the history
Make IDNA dependency non-optional
  • Loading branch information
valenting committed Sep 7, 2022
2 parents a3df365 + eaa23e5 commit 587e962
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 24 deletions.
4 changes: 2 additions & 2 deletions url/Cargo.toml
Expand Up @@ -29,12 +29,12 @@ debugger_test_parser = "0.1"

[dependencies]
form_urlencoded = { version = "1.0.0", path = "../form_urlencoded" }
idna = { version = "0.2.0", path = "../idna", optional = true }
idna = { version = "0.2.0", path = "../idna" }
percent-encoding = { version = "2.1.0", path = "../percent_encoding" }
serde = {version = "1.0", optional = true, features = ["derive"]}

[features]
default = ["idna"]
default = []
# UNSTABLE FEATURES (requires Rust nightly)
# Enable to use the #[debugger_visualizer] attribute.
debugger_visualizer = []
Expand Down
13 changes: 0 additions & 13 deletions url/src/host.rs
Expand Up @@ -162,22 +162,9 @@ impl Host<String> {
}

/// convert domain with idna
#[cfg(feature = "idna")]
fn domain_to_ascii(domain: &str) -> Result<String, ParseError> {
idna::domain_to_ascii(domain).map_err(Into::into)
}

/// checks domain is ascii
#[cfg(not(feature = "idna"))]
fn domain_to_ascii(domain: &str) -> Result<String, ParseError> {
// without idna feature, we can't verify that xn-- domains correctness
let domain = domain.to_lowercase();
if domain.is_ascii() && domain.split('.').all(|s| !s.starts_with("xn--")) {
Ok(domain)
} else {
Err(ParseError::InvalidDomainCharacter)
}
}
}

impl<S: AsRef<str>> fmt::Display for Host<S> {
Expand Down
1 change: 0 additions & 1 deletion url/src/origin.rs
Expand Up @@ -86,7 +86,6 @@ impl Origin {
}

/// <https://html.spec.whatwg.org/multipage/#unicode-serialisation-of-an-origin>
#[cfg(feature = "idna")]
pub fn unicode_serialization(&self) -> String {
match *self {
Origin::Opaque(_) => "null".to_owned(),
Expand Down
1 change: 0 additions & 1 deletion url/src/parser.rs
Expand Up @@ -87,7 +87,6 @@ simple_enum_error! {
Overflow => "URLs more than 4 GB are not supported",
}

#[cfg(feature = "idna")]
impl From<::idna::Errors> for ParseError {
fn from(_: ::idna::Errors) -> ParseError {
ParseError::IdnaError
Expand Down
1 change: 0 additions & 1 deletion url/src/quirks.rs
Expand Up @@ -66,7 +66,6 @@ pub fn domain_to_ascii(domain: &str) -> String {
}

/// https://url.spec.whatwg.org/#dom-url-domaintounicode
#[cfg(feature = "idna")]
pub fn domain_to_unicode(domain: &str) -> String {
match Host::parse(domain) {
Ok(Host::Domain(ref domain)) => {
Expand Down
3 changes: 0 additions & 3 deletions url/tests/data.rs
Expand Up @@ -15,7 +15,6 @@ use url::{quirks, Url};

#[test]
fn urltestdata() {
#[cfg(not(feature = "idna"))]
let idna_skip_inputs = [
"http://www.foo。bar.com",
"http://Go.com",
Expand Down Expand Up @@ -46,7 +45,6 @@ fn urltestdata() {
let input = entry.take_string("input");
let failure = entry.take_key("failure").is_some();

#[cfg(not(feature = "idna"))]
{
if idna_skip_inputs.contains(&input.as_str()) {
continue;
Expand Down Expand Up @@ -133,7 +131,6 @@ fn setters_tests() {
let mut tests = json.take_key(attr).unwrap();
for mut test in tests.as_array_mut().unwrap().drain(..) {
let comment = test.take_key("comment").map(|s| s.string());
#[cfg(not(feature = "idna"))]
{
if let Some(comment) = comment.as_ref() {
if comment.starts_with("IDNA Nontransitional_Processing") {
Expand Down
3 changes: 0 additions & 3 deletions url/tests/unit.rs
Expand Up @@ -304,7 +304,6 @@ fn host_serialization() {
);
}

#[cfg(feature = "idna")]
#[test]
fn test_idna() {
assert!("http://goșu.ro".parse::<Url>().is_ok());
Expand Down Expand Up @@ -540,7 +539,6 @@ fn test_origin_opaque() {
assert!(!&Url::parse("blob:malformed//").unwrap().origin().is_tuple())
}

#[cfg(feature = "idna")]
#[test]
fn test_origin_unicode_serialization() {
let data = [
Expand Down Expand Up @@ -713,7 +711,6 @@ fn test_set_href() {
);
}

#[cfg(feature = "idna")]
#[test]
fn test_domain_encoding_quirks() {
use url::quirks::{domain_to_ascii, domain_to_unicode};
Expand Down

0 comments on commit 587e962

Please sign in to comment.