File tree Expand file tree Collapse file tree 2 files changed +17
-11
lines changed Expand file tree Collapse file tree 2 files changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -5,12 +5,14 @@ username = ${ (!(":" | "@" | WHITE_SPACE) ~ ANY)+ }
55password = ${ (!("@" | WHITE_SPACE) ~ ANY)+ }
66userinfo = ${ username ~ (":" ~ password)? ~ "@" }
77
8- host = ${ ipv4 | ipv6 | hostname }
8+ // this rule is used to check if the hostname is actually
9+ // a valid ipv4 address as hostname rule matches any ipv4
10+ ipv4 = ${ SOI ~ (ASCII_DIGIT{1, 3} ~ "."){3} ~ ASCII_DIGIT{1, 3} ~ EOI }
11+ host = ${ ipv6 | hostname }
912domain_part = ${ (!(":" | "?" | "/" | "#" | "." | WHITE_SPACE) ~ ANY)+ }
1013tld = ${ (!(":" | "?" | "/" | "#" | WHITE_SPACE) ~ ANY)+ }
1114hostname = ${ (((domain_part ~ ".")+ ~ tld) | domain_part) }
1215
13- ipv4 = ${ (ASCII_DIGIT{1, 3} ~ "."){3} ~ ASCII_DIGIT{1, 3} }
1416ipv6 = ${ "[" ~ (ASCII_HEX_DIGIT{,4} ~ ":"){2, 7} ~ ASCII_HEX_DIGIT{,4} ~ "]" }
1517
1618encoded_char = ${ "%" ~ ASCII_DIGIT{2} }
Original file line number Diff line number Diff line change @@ -597,15 +597,18 @@ impl<'url> Url<'url> {
597597 let host_pair = p. into_inner ( ) . next ( ) . unwrap ( ) ;
598598 match host_pair. as_rule ( ) {
599599 Rule :: hostname => {
600- host = Some ( Host :: Hostname ( Hostname :: from_str ( host_pair. as_str ( ) ) ) )
601- }
602- Rule :: ipv4 => {
603- host = Some (
604- Ipv4Addr :: from_str ( host_pair. as_str ( ) )
605- . map ( IpAddr :: from)
606- . map ( Host :: Ip )
607- . map_err ( |_| Error :: InvalidIPv4 ) ?,
608- ) ;
600+ if let Ok ( ipv4) =
601+ UrlParser :: parse ( Rule :: ipv4, host_pair. as_str ( ) ) . map ( |p| p. as_str ( ) )
602+ {
603+ host = Some (
604+ Ipv4Addr :: from_str ( ipv4)
605+ . map ( IpAddr :: from)
606+ . map ( Host :: Ip )
607+ . map_err ( |_| Error :: InvalidIPv4 ) ?,
608+ ) ;
609+ } else {
610+ host = Some ( Host :: Hostname ( Hostname :: from_str ( host_pair. as_str ( ) ) ) )
611+ }
609612 }
610613
611614 Rule :: ipv6 => {
@@ -984,6 +987,7 @@ mod tests {
984987 "http://full.custom-tld.test.b32.i2p" ,
985988 "https://alex:adore-la-quiche@avec-des-œufs.be#et-des-lardons" ,
986989 "https://%40lex:adore:la:quiche@%61vec-des-œufs.be/../../..some/directory/traversal/../#et-des-lardons" ,
990+ "https://44.129.205.92.host.secureserver.net" ,
987991 ] ;
988992
989993 for url in test_urls {
You can’t perform that action at this time.
0 commit comments