Skip to content

Commit 4688c72

Browse files
authored
Merge pull request #14 from spk/fix-127.0.0.1-host-panic
Use host_str instead domain for HostInternal
2 parents 953d1f0 + 19bd3b4 commit 4688c72

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl<'a> RobotFileParser<'a> {
221221
disallow_all: Cell::new(false),
222222
allow_all: Cell::new(false),
223223
url: parsed_url.clone(),
224-
host: parsed_url.domain().unwrap().to_owned(),
224+
host: parsed_url.host_str().unwrap().to_owned(),
225225
path: parsed_url.path().to_owned(),
226226
last_checked: Cell::new(0i64),
227227
}
@@ -246,7 +246,7 @@ impl<'a> RobotFileParser<'a> {
246246
pub fn set_url<T: AsRef<str>>(&mut self, url: T) {
247247
let parsed_url = Url::parse(url.as_ref()).unwrap();
248248
self.url = parsed_url.clone();
249-
self.host = parsed_url.domain().unwrap().to_owned();
249+
self.host = parsed_url.host_str().unwrap().to_owned();
250250
self.path = parsed_url.path().to_owned();
251251
self.last_checked.set(0i64);
252252
}

tests/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,9 @@ fn test_robots_text_request_rate() {
268268
let req_rate = parser.get_req_rate("Google");
269269
assert!(req_rate.is_none());
270270
}
271+
272+
#[test]
273+
fn test_robots_127_0_0_1() {
274+
// Ensure it does not panic
275+
RobotFileParser::new("http://127.0.0.1:4000/robots.txt");
276+
}

0 commit comments

Comments
 (0)