Skip to content

Commit 1e10525

Browse files
committedOct 30, 2017
Do not parse an empty string as an IpAddress.
This is more likely to result in downstream confusion than not. Let downstream code decide exactly what it wants to do with an empty string; be conservative here.
1 parent 7a2271d commit 1e10525

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed
 

‎src/parsers.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,6 @@ impl<'a> Parser<'a> {
127127
}
128128

129129
fn accept_ip(&mut self) -> Result<IpAddress> {
130-
if let Some(()) = self.try(|p| p.accept_eof()) {
131-
return Ok(IpAddress::Unspecified)
132-
}
133130
if let Some(ipv4) = self.try(|p| p.accept_ipv4()) {
134131
return Ok(IpAddress::Ipv4(ipv4))
135132
}
@@ -158,7 +155,7 @@ impl FromStr for Ipv4Address {
158155
impl FromStr for IpAddress {
159156
type Err = ();
160157

161-
/// Parse a string representation of an IPv4 address.
158+
/// Parse a string representation of an IP address.
162159
fn from_str(s: &str) -> Result<IpAddress> {
163160
Parser::new(s).until_eof(|p| p.accept_ip())
164161
}
@@ -229,8 +226,7 @@ mod test {
229226

230227
#[test]
231228
fn test_ip() {
232-
assert_eq!(IpAddress::from_str(""),
233-
Ok(IpAddress::Unspecified));
229+
assert_eq!(IpAddress::from_str(""), Err(()));
234230
assert_eq!(IpAddress::from_str("1.2.3.4"),
235231
Ok(IpAddress::Ipv4(Ipv4Address([1, 2, 3, 4]))));
236232
assert_eq!(IpAddress::from_str("x"), Err(()));

0 commit comments

Comments
 (0)