Skip to content

Commit 681567b

Browse files
committed
servo: Merge #19411 - Replace parse-hosts crate with 10 lines of code (from servo:parse-hosts); r=nox
This removes 3927 lines of Rust code in 6 crates from the dependency graph: parse-hosts, multistr, bow, extra-default, len-trait, and push-trait. One of these crates doesn’t build in today’s Nightly: rust-lang/rust#46328 Source-Repo: https://github.com/servo/servo Source-Revision: ae3c3ba1c2f265e01a377f73f4a9016aded54367 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : b7d289b529cbdba3679c1e6c626264d90dd648d2
1 parent 6363cad commit 681567b

File tree

4 files changed

+12
-66
lines changed

4 files changed

+12
-66
lines changed

servo/Cargo.lock

Lines changed: 0 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

servo/components/net/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ mime_guess = "1.8.0"
2828
msg = {path = "../msg"}
2929
net_traits = {path = "../net_traits"}
3030
openssl = "0.9"
31-
parse-hosts = "0.5.0"
3231
profile_traits = {path = "../profile_traits"}
3332
serde = "1.0"
3433
serde_json = "1.0"

servo/components/net/hosts.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use parse_hosts::HostsFile;
65
use std::borrow::Cow;
76
use std::collections::HashMap;
87
use std::env;
98
use std::fs::File;
109
use std::io::{BufReader, Read};
11-
use std::net::IpAddr;
10+
use std::net::{IpAddr, Ipv4Addr};
1211
use std::sync::Mutex;
1312

1413
lazy_static! {
@@ -32,10 +31,17 @@ pub fn replace_host_table(table: HashMap<String, IpAddr>) {
3231
}
3332

3433
pub fn parse_hostsfile(hostsfile_content: &str) -> HashMap<String, IpAddr> {
35-
HostsFile::read_buffered(hostsfile_content.as_bytes())
36-
.pairs()
37-
.filter_map(Result::ok)
38-
.collect()
34+
hostsfile_content.lines().filter_map(|line| {
35+
let mut iter = line.split('#').next().unwrap().split_whitespace();
36+
Some((iter.next()?.parse().ok()?, iter))
37+
}).flat_map(|(ip, hosts)| {
38+
hosts.filter(|host| {
39+
let invalid = ['\0', '\t', '\n', '\r', ' ', '#', '%', '/', ':', '?', '@', '[', '\\', ']'];
40+
host.parse::<Ipv4Addr>().is_err() && !host.contains(&invalid[..])
41+
}).map(move |host| {
42+
(host.to_owned(), ip)
43+
})
44+
}).collect()
3945
}
4046

4147
pub fn replace_host(host: &str) -> Cow<str> {

servo/components/net/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ extern crate mime_guess;
2424
extern crate msg;
2525
extern crate net_traits;
2626
extern crate openssl;
27-
extern crate parse_hosts;
2827
extern crate profile_traits;
2928
#[macro_use] extern crate serde;
3029
extern crate serde_json;

0 commit comments

Comments
 (0)