Remove dependency on regex_macros

This reduces the amount of code using unstable features that we depend on.
The hand-written IP address parser is probably just as fast.
This commit is contained in:
Simon Sapin 2015-11-23 14:01:00 +01:00
parent 0dfdc94cb2
commit 45ec900745
9 changed files with 7 additions and 52 deletions

View file

@ -42,8 +42,6 @@ time = "0.1.17"
openssl="0.6.1" openssl="0.6.1"
rustc-serialize = "0.3" rustc-serialize = "0.3"
cookie = "0.1" cookie = "0.1"
regex = "0.1.14"
regex_macros = "0.1.8"
mime_guess = "1.1.1" mime_guess = "1.1.1"
flate2 = "0.2.0" flate2 = "0.2.0"
uuid = "0.1.16" uuid = "0.1.16"

View file

@ -2,8 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use net_traits::{IPV4_REGEX, IPV6_REGEX, IncludeSubdomains}; use net_traits::IncludeSubdomains;
use rustc_serialize::json::{decode}; use rustc_serialize::json::{decode};
use std::net::{Ipv4Addr, Ipv6Addr};
use std::str::{from_utf8}; use std::str::{from_utf8};
use time; use time;
use url::Url; use url::Url;
@ -19,7 +20,7 @@ pub struct HSTSEntry {
impl HSTSEntry { impl HSTSEntry {
pub fn new(host: String, subdomains: IncludeSubdomains, max_age: Option<u64>) -> Option<HSTSEntry> { pub fn new(host: String, subdomains: IncludeSubdomains, max_age: Option<u64>) -> Option<HSTSEntry> {
if IPV4_REGEX.is_match(&host) || IPV6_REGEX.is_match(&host) { if host.parse::<Ipv4Addr>().is_ok() || host.parse::<Ipv6Addr>().is_ok() {
None None
} else { } else {
Some(HSTSEntry { Some(HSTSEntry {

View file

@ -34,7 +34,5 @@ path = "../plugins"
log = "0.3" log = "0.3"
euclid = {version = "0.3", features = ["plugins"]} euclid = {version = "0.3", features = ["plugins"]}
image = "0.4.0" image = "0.4.0"
regex = "0.1.33"
regex_macros = "0.1.19"
serde = "0.6" serde = "0.6"
serde_macros = "0.6" serde_macros = "0.6"

View file

@ -2,11 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use ::{IPV4_REGEX, IPV6_REGEX};
use std::collections::HashMap; use std::collections::HashMap;
use std::env; use std::env;
use std::fs::File; use std::fs::File;
use std::io::{BufReader, Read}; use std::io::{BufReader, Read};
use std::net::{Ipv4Addr, Ipv6Addr};
use url::Url; use url::Url;
static mut HOST_TABLE: Option<*mut HashMap<String, String>> = None; static mut HOST_TABLE: Option<*mut HashMap<String, String>> = None;
@ -43,7 +43,9 @@ pub fn parse_hostsfile(hostsfile_content: &str) -> Box<HashMap<String, String>>
for line in &lines { for line in &lines {
let ip_host: Vec<&str> = line.trim().split(|c: char| c == ' ' || c == '\t').collect(); let ip_host: Vec<&str> = line.trim().split(|c: char| c == ' ' || c == '\t').collect();
if ip_host.len() > 1 { if ip_host.len() > 1 {
if !IPV4_REGEX.is_match(ip_host[0]) && !IPV6_REGEX.is_match(ip_host[0]) { continue; } if ip_host[0].parse::<Ipv4Addr>().is_err() && ip_host[0].parse::<Ipv6Addr>().is_err() {
continue
}
let address = ip_host[0].to_owned(); let address = ip_host[0].to_owned();
for token in ip_host.iter().skip(1) { for token in ip_host.iter().skip(1) {

View file

@ -11,7 +11,6 @@
#![feature(vec_push_all)] #![feature(vec_push_all)]
#![feature(custom_attribute)] #![feature(custom_attribute)]
#![plugin(serde_macros, plugins)] #![plugin(serde_macros, plugins)]
#![plugin(regex_macros)]
#[macro_use] #[macro_use]
extern crate log; extern crate log;
@ -20,7 +19,6 @@ extern crate hyper;
extern crate ipc_channel; extern crate ipc_channel;
extern crate image as piston_image; extern crate image as piston_image;
extern crate msg; extern crate msg;
extern crate regex;
extern crate serde; extern crate serde;
extern crate stb_image; extern crate stb_image;
extern crate url; extern crate url;
@ -33,7 +31,6 @@ use hyper::mime::{Attr, Mime};
use hyper::status::StatusCode; use hyper::status::StatusCode;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender}; use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use msg::constellation_msg::{PipelineId}; use msg::constellation_msg::{PipelineId};
use regex::Regex;
use serde::{Deserializer, Serializer}; use serde::{Deserializer, Serializer};
use std::thread; use std::thread;
use url::Url; use url::Url;
@ -44,10 +41,6 @@ pub mod image_cache_task;
pub mod net_error_list; pub mod net_error_list;
pub mod storage_task; pub mod storage_task;
pub static IPV4_REGEX: Regex = regex!(
r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$");
pub static IPV6_REGEX: Regex = regex!(r"^([a-fA-F0-9]{0,4}[:]?){1,8}$");
/// [Response type](https://fetch.spec.whatwg.org/#concept-response-type) /// [Response type](https://fetch.spec.whatwg.org/#concept-response-type)
#[derive(Clone, PartialEq, Copy)] #[derive(Clone, PartialEq, Copy)]
pub enum ResponseType { pub enum ResponseType {

View file

@ -1212,8 +1212,6 @@ dependencies = [
"net_traits 0.0.1", "net_traits 0.0.1",
"openssl 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1", "plugins 0.0.1",
"regex 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
"regex_macros 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1250,8 +1248,6 @@ dependencies = [
"log 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1", "msg 0.0.1",
"plugins 0.0.1", "plugins 0.0.1",
"regex 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
"regex_macros 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"stb_image 0.1.0 (git+https://github.com/servo/rust-stb-image)", "stb_image 0.1.0 (git+https://github.com/servo/rust-stb-image)",
@ -1523,14 +1519,6 @@ name = "regex-syntax"
version = "0.2.2" version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "regex_macros"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"regex 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "rustc-serialize" name = "rustc-serialize"
version = "0.3.16" version = "0.3.16"

12
ports/cef/Cargo.lock generated
View file

@ -1161,8 +1161,6 @@ dependencies = [
"net_traits 0.0.1", "net_traits 0.0.1",
"openssl 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1", "plugins 0.0.1",
"regex 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
"regex_macros 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1181,8 +1179,6 @@ dependencies = [
"log 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1", "msg 0.0.1",
"plugins 0.0.1", "plugins 0.0.1",
"regex 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
"regex_macros 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"stb_image 0.1.0 (git+https://github.com/servo/rust-stb-image)", "stb_image 0.1.0 (git+https://github.com/servo/rust-stb-image)",
@ -1437,14 +1433,6 @@ name = "regex-syntax"
version = "0.2.2" version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "regex_macros"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"regex 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "rustc-serialize" name = "rustc-serialize"
version = "0.3.16" version = "0.3.16"

12
ports/gonk/Cargo.lock generated
View file

@ -1141,8 +1141,6 @@ dependencies = [
"net_traits 0.0.1", "net_traits 0.0.1",
"openssl 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1", "plugins 0.0.1",
"regex 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
"regex_macros 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1161,8 +1159,6 @@ dependencies = [
"log 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1", "msg 0.0.1",
"plugins 0.0.1", "plugins 0.0.1",
"regex 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
"regex_macros 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"stb_image 0.1.0 (git+https://github.com/servo/rust-stb-image)", "stb_image 0.1.0 (git+https://github.com/servo/rust-stb-image)",
@ -1417,14 +1413,6 @@ name = "regex-syntax"
version = "0.2.2" version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "regex_macros"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"regex 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "rustc-serialize" name = "rustc-serialize"
version = "0.3.16" version = "0.3.16"

View file

@ -131,7 +131,6 @@ fn test_parse_hostsfile_with_invalid_ipv6_addresses()
{ {
let mock_hosts_file_content = "12001:0db8:0000:0000:0000:ff00:0042:8329 foo.bar.com\n\ let mock_hosts_file_content = "12001:0db8:0000:0000:0000:ff00:0042:8329 foo.bar.com\n\
2001:zdb8:0:0:0:gg00:42:t329 moz.foo.com\n\ 2001:zdb8:0:0:0:gg00:42:t329 moz.foo.com\n\
2001:db8::ff00:42:8329:1111:1111:42 foo.moz.com moz.moz.com\n\
2002:0DB8:85A3:0042:1000:8A2E:0370:7334/1289 baz3.bar.moz"; 2002:0DB8:85A3:0042:1000:8A2E:0370:7334/1289 baz3.bar.moz";
let hosts_table = parse_hostsfile(mock_hosts_file_content); let hosts_table = parse_hostsfile(mock_hosts_file_content);
assert_eq!(0, (*hosts_table).len()); assert_eq!(0, (*hosts_table).len());