Explorar o código

init commit to make idna optional

lishuo %!s(int64=4) %!d(string=hai) anos
pai
achega
55322758aa
Modificáronse 6 ficheiros con 17 adicións e 1 borrados
  1. 4 1
      url/Cargo.toml
  2. 5 0
      url/src/host.rs
  3. 5 0
      url/src/origin.rs
  4. 1 0
      url/src/parser.rs
  5. 1 0
      url/src/quirks.rs
  6. 1 0
      url/tests/unit.rs

+ 4 - 1
url/Cargo.toml

@@ -25,11 +25,14 @@ bencher = "0.1"
 
 [dependencies]
 form_urlencoded = { version = "1.0.0", path = "../form_urlencoded" }
-idna = { version = "0.2.0", path = "../idna" }
+idna = { version = "0.2.0", path = "../idna", optional = true }
 matches = "0.1"
 percent-encoding = { version = "2.1.0", path = "../percent_encoding" }
 serde = {version = "1.0", optional = true, features = ["derive"]}
 
+[features]
+default = ["idna"]
+
 [[bench]]
 name = "parse_url"
 path = "benches/parse_url.rs"

+ 5 - 0
url/src/host.rs

@@ -82,7 +82,12 @@ impl Host<String> {
             return parse_ipv6addr(&input[1..input.len() - 1]).map(Host::Ipv6);
         }
         let domain = percent_decode(input.as_bytes()).decode_utf8_lossy();
+
+        #[cfg(feature = "idna")]
         let domain = idna::domain_to_ascii(&domain)?;
+        #[cfg(not(feature = "idna"))]
+        let domain = domain.to_string();
+
         if domain.is_empty() {
             return Err(ParseError::EmptyHost);
         }

+ 5 - 0
url/src/origin.rs

@@ -9,6 +9,7 @@
 use crate::host::Host;
 use crate::parser::default_port;
 use crate::Url;
+#[cfg(feature = "idna")]
 use idna::domain_to_unicode;
 use std::sync::atomic::{AtomicUsize, Ordering};
 
@@ -93,7 +94,11 @@ impl Origin {
             Origin::Tuple(ref scheme, ref host, port) => {
                 let host = match *host {
                     Host::Domain(ref domain) => {
+                        #[cfg(feature = "idna")]
                         let (domain, _errors) = domain_to_unicode(domain);
+                        #[cfg(not(feature = "idna"))]
+                        let domain = domain.clone();
+
                         Host::Domain(domain)
                     }
                     _ => host.clone(),

+ 1 - 0
url/src/parser.rs

@@ -93,6 +93,7 @@ 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

+ 1 - 0
url/src/quirks.rs

@@ -23,6 +23,7 @@ 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)) => {

+ 1 - 0
url/tests/unit.rs

@@ -703,6 +703,7 @@ fn test_set_href() {
     );
 }
 
+#[cfg(feature = "idna")]
 #[test]
 fn test_domain_encoding_quirks() {
     use url::quirks::{domain_to_ascii, domain_to_unicode};