Răsfoiți Sursa

Merge pull request #790 from crowlKats/remove_idna

Make IDNA dependency non-optional
Valentin Gosu 4 ani în urmă
părinte
comite
587e9628a9
7 a modificat fișierele cu 2 adăugiri și 24 ștergeri
  1. 2 2
      url/Cargo.toml
  2. 0 13
      url/src/host.rs
  3. 0 1
      url/src/origin.rs
  4. 0 1
      url/src/parser.rs
  5. 0 1
      url/src/quirks.rs
  6. 0 3
      url/tests/data.rs
  7. 0 3
      url/tests/unit.rs

+ 2 - 2
url/Cargo.toml

@@ -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 = []

+ 0 - 13
url/src/host.rs

@@ -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> {

+ 0 - 1
url/src/origin.rs

@@ -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(),

+ 0 - 1
url/src/parser.rs

@@ -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

+ 0 - 1
url/src/quirks.rs

@@ -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)) => {

+ 0 - 3
url/tests/data.rs

@@ -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",
@@ -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;
@@ -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") {

+ 0 - 3
url/tests/unit.rs

@@ -304,7 +304,6 @@ fn host_serialization() {
     );
 }
 
-#[cfg(feature = "idna")]
 #[test]
 fn test_idna() {
     assert!("http://goșu.ro".parse::<Url>().is_ok());
@@ -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 = [
@@ -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};