From 19bd3b4cf60d6c71eefb9ae1540a7e2c753f19e2 Mon Sep 17 00:00:00 2001 From: Laurent Arnoud Date: Sun, 11 Mar 2018 22:05:14 +0100 Subject: [PATCH] Use host_str instead domain for HostInternal --- src/lib.rs | 4 ++-- tests/lib.rs | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1c603f7..d466579 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -221,7 +221,7 @@ impl<'a> RobotFileParser<'a> { disallow_all: Cell::new(false), allow_all: Cell::new(false), url: parsed_url.clone(), - host: parsed_url.domain().unwrap().to_owned(), + host: parsed_url.host_str().unwrap().to_owned(), path: parsed_url.path().to_owned(), last_checked: Cell::new(0i64), } @@ -246,7 +246,7 @@ impl<'a> RobotFileParser<'a> { pub fn set_url>(&mut self, url: T) { let parsed_url = Url::parse(url.as_ref()).unwrap(); self.url = parsed_url.clone(); - self.host = parsed_url.domain().unwrap().to_owned(); + self.host = parsed_url.host_str().unwrap().to_owned(); self.path = parsed_url.path().to_owned(); self.last_checked.set(0i64); } diff --git a/tests/lib.rs b/tests/lib.rs index 9a43848..0c6a8b5 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -268,3 +268,9 @@ fn test_robots_text_request_rate() { let req_rate = parser.get_req_rate("Google"); assert!(req_rate.is_none()); } + +#[test] +fn test_robots_127_0_0_1() { + // Ensure it does not panic + RobotFileParser::new("http://127.0.0.1:4000/robots.txt"); +}