Sfoglia il codice sorgente

Opaque parser should parse IPv6 first

Valentin Gosu 9 anni fa
parent
commit
954ce1ff27
1 ha cambiato i file con 6 aggiunte e 0 eliminazioni
  1. 6 0
      src/host.rs

+ 6 - 0
src/host.rs

@@ -161,6 +161,12 @@ impl Host<String> {
 
 
     // <https://url.spec.whatwg.org/#concept-opaque-host-parser>
     // <https://url.spec.whatwg.org/#concept-opaque-host-parser>
     pub fn parse_opaque(input: &str) -> Result<Self, ParseError> {
     pub fn parse_opaque(input: &str) -> Result<Self, ParseError> {
+        if input.starts_with('[') {
+            if !input.ends_with(']') {
+                return Err(ParseError::InvalidIpv6Address)
+            }
+            return parse_ipv6addr(&input[1..input.len() - 1]).map(Host::Ipv6)
+        }
         if input.find(|c| matches!(c,
         if input.find(|c| matches!(c,
             '\0' | '\t' | '\n' | '\r' | ' ' | '#' | '/' | ':' | '?' | '@' | '[' | '\\' | ']'
             '\0' | '\t' | '\n' | '\r' | ' ' | '#' | '/' | ':' | '?' | '@' | '[' | '\\' | ']'
         )).is_some() {
         )).is_some() {