diff --git a/idna/src/uts46.rs b/idna/src/uts46.rs index af2a6313..2843d4f4 100644 --- a/idna/src/uts46.rs +++ b/idna/src/uts46.rs @@ -224,10 +224,12 @@ fn processing(domain: &str, flags: Flags, errors: &mut Vec) -> String { } let normalized: String = mapped.nfc().collect(); let mut validated = String::new(); + let mut first = true; for label in normalized.split('.') { - if validated.len() > 0 { + if !first { validated.push('.'); } + first = false; if label.starts_with("xn--") { match punycode::decode_to_string(&label["xn--".len()..]) { Some(decoded_label) => { @@ -273,10 +275,12 @@ pub struct Errors(Vec); pub fn to_ascii(domain: &str, flags: Flags) -> Result { let mut errors = Vec::new(); let mut result = String::new(); + let mut first = true; for label in processing(domain, flags, &mut errors).split('.') { - if result.len() > 0 { + if !first { result.push('.'); } + first = false; if label.is_ascii() { result.push_str(label); } else { diff --git a/tests/urltestdata.json b/tests/urltestdata.json index d73ffec1..6c520f8a 100644 --- a/tests/urltestdata.json +++ b/tests/urltestdata.json @@ -4373,5 +4373,22 @@ "search": "?qux", "searchParams": "", "hash": "#foo%08bar" + }, + "# Correct handling of empty domain segments", + { + "input": "http://../", + "base": "about:blank", + "href": "http://../", + "origin": "http://..", + "protocol": "http:", + "username": "", + "password": "", + "host": "..", + "hostname": "..", + "port": "", + "pathname": "/", + "search": "", + "searchParams": "", + "hash": "" } ]