From 0a23b31f8b6584b260fbd39d0135e45c677fc079 Mon Sep 17 00:00:00 2001 From: Jesse Ezell Date: Fri, 1 Jul 2016 01:20:55 -0700 Subject: [PATCH] Relax url parsing to support youtube URLs which don't strictly follow the rules --- idna/src/lib.rs | 2 ++ idna/src/uts46.rs | 4 +++- tests/unit.rs | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/idna/src/lib.rs b/idna/src/lib.rs index bdeafe44..94474e68 100644 --- a/idna/src/lib.rs +++ b/idna/src/lib.rs @@ -51,6 +51,7 @@ pub fn domain_to_ascii(domain: &str) -> Result { use_std3_ascii_rules: false, transitional_processing: true, // XXX: switch when Firefox does verify_dns_length: false, + relax_future_extension_validation: true }) } @@ -69,5 +70,6 @@ pub fn domain_to_unicode(domain: &str) -> (String, Result<(), uts46::Errors>) { // Unused: transitional_processing: true, verify_dns_length: false, + relax_future_extension_validation: true }) } diff --git a/idna/src/uts46.rs b/idna/src/uts46.rs index bfe12ff2..a7ce3397 100644 --- a/idna/src/uts46.rs +++ b/idna/src/uts46.rs @@ -202,7 +202,7 @@ fn validate(label: &str, flags: Flags, errors: &mut Vec) { let mut chars = label.chars().skip(2); let third = chars.next(); let fourth = chars.next(); - (third, fourth) == (Some('-'), Some('-')) + !flags.relax_future_extension_validation && (third, fourth) == (Some('-'), Some('-')) } || label.starts_with("-") || label.ends_with("-") || label.chars().next().map_or(false, is_combining_mark) @@ -252,6 +252,8 @@ pub struct Flags { pub use_std3_ascii_rules: bool, pub transitional_processing: bool, pub verify_dns_length: bool, + /// http://www.unicode.org/reports/tr46/#Validity_Criteria 'Some implementations appear to consider such extentions unlikely, and allow labels such as "r3---sn-apo3qvuoxuxbt-j5pe".' + pub relax_future_extension_validation: bool } #[derive(PartialEq, Eq, Clone, Copy, Debug)] diff --git a/tests/unit.rs b/tests/unit.rs index 55906b8e..474ac62b 100644 --- a/tests/unit.rs +++ b/tests/unit.rs @@ -192,6 +192,7 @@ fn host_serialization() { fn test_idna() { assert!("http://goșu.ro".parse::().is_ok()); assert_eq!(Url::parse("http://☃.net/").unwrap().host(), Some(Host::Domain("xn--n3h.net"))); + assert!("https://r2---sn-huoa-cvhl.googlevideo.com/crossdomain.xml".parse::().is_ok()); } #[test]