Преглед изворни кода

Reject leading + in IPv4 address.

Simon Sapin пре 10 година
родитељ
комит
5838ff325d
2 измењених фајлова са 5 додато и 0 уклоњено
  1. 3 0
      src/host.rs
  2. 2 0
      tests/tests.rs

+ 3 - 0
src/host.rs

@@ -94,6 +94,9 @@ fn parse_ipv4number(mut input: &str) -> ParseResult<u32> {
     if input.is_empty() {
         return Ok(0);
     }
+    if input.starts_with("+") {
+        return Err(ParseError::InvalidIpv4Address)
+    }
     match u32::from_str_radix(&input, r) {
         Ok(number) => return Ok(number),
         Err(_) => Err(ParseError::InvalidIpv4Address),

+ 2 - 0
tests/tests.rs

@@ -355,10 +355,12 @@ fn host() {
     let a = Host::parse("www.mozilla.org").unwrap();
     let b = Host::parse("1.35.33.49").unwrap();
     let c = Host::parse("[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]").unwrap();
+    let d = Host::parse("1.35.+33.49").unwrap();
     assert_eq!(a, Host::Domain("www.mozilla.org".to_owned()));
     assert_eq!(b, Host::Ipv4(Ipv4Addr::new(1, 35, 33, 49)));
     assert_eq!(c, Host::Ipv6(Ipv6Addr::new(0x2001, 0x0db8, 0x85a3, 0x08d3,
         0x1319, 0x8a2e, 0x0370, 0x7344)));
+    assert_eq!(d, Host::Domain("1.35.+33.49".to_owned()));
     assert_eq!(Host::parse("[::]").unwrap(), Host::Ipv6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)));
     assert_eq!(Host::parse("[::1]").unwrap(), Host::Ipv6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)));
     assert_eq!(Host::parse("0x1.0X23.0x21.061").unwrap(), Host::Ipv4(Ipv4Addr::new(1, 35, 33, 49)));