speedreader: replace chrono dep with time-rs.

The maintainers of the `chrono` crate haven't been responsive to
CVE fixes. Replace our use of that crate with similar support
from the `time` crate.

This addresses `cargo audit` reports

- https://rustsec.org/advisories/RUSTSEC-2020-0159
- https://rustsec.org/advisories/RUSTSEC-2020-0071

See https://github.com/chronotope/chrono/pull/578 for discussion.
This commit is contained in:
Ralph Giles
2021-11-09 14:15:22 -08:00
parent 497bb5c817
commit 396d931664
4 changed files with 43 additions and 82 deletions
+21 -46
View File
@@ -53,19 +53,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"libc",
"num-integer",
"num-traits",
"time",
"winapi",
]
[[package]]
name = "cloudabi"
version = "0.0.3"
@@ -186,9 +173,9 @@ dependencies = [
[[package]]
name = "flate2"
version = "1.0.20"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd3aec53de10fe96d7d8c565eb17f2c687bb5518a2ec453b5b1252964526abe0"
checksum = "1e6988e897c1c9c485f43b47a529cef42fde0547f9d8d41a7062518f1d8fc53f"
dependencies = [
"cfg-if 1.0.0",
"crc32fast",
@@ -269,9 +256,9 @@ dependencies = [
[[package]]
name = "itoa"
version = "0.4.6"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
name = "kuchiki"
@@ -404,25 +391,6 @@ version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
[[package]]
name = "num-integer"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [
"autocfg 1.0.0",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611"
dependencies = [
"autocfg 1.0.0",
]
[[package]]
name = "percent-encoding"
version = "2.1.0"
@@ -733,13 +701,13 @@ name = "readability"
version = "0.1.4"
dependencies = [
"bitflags",
"chrono",
"html5ever",
"kuchiki",
"lazy_static",
"regex",
"serde_json",
"thiserror",
"time",
"url",
]
@@ -831,9 +799,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.64"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79"
checksum = "e466864e431129c7e0d3476b92f20458e5879919a0596c6472738d9fa2d342f8"
dependencies = [
"itoa",
"ryu",
@@ -964,18 +932,18 @@ checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c"
[[package]]
name = "thiserror"
version = "1.0.26"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93119e4feac1cbe6c798c34d3a53ea0026b0b1de6a120deef895137c0529bfe2"
checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.26"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "060d69a0afe7796bf42e9e2ff91f5ee691fb15c53d38b4b62a9a53eb23164745"
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
dependencies = [
"proc-macro2",
"quote",
@@ -993,14 +961,21 @@ dependencies = [
[[package]]
name = "time"
version = "0.1.43"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
checksum = "99beeb0daeac2bd1e86ac2c21caddecb244b39a093594da1a661ec2060c7aedd"
dependencies = [
"itoa",
"libc",
"winapi",
"time-macros",
]
[[package]]
name = "time-macros"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25eb0ca3468fc0acc11828786797f6ef9aa1555e4a211a60d64cc8e4d1be47d6"
[[package]]
name = "tinyvec"
version = "1.4.0"
+11 -27
View File
@@ -109,19 +109,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"libc",
"num-integer",
"num-traits",
"time",
"winapi",
]
[[package]]
name = "clap"
version = "2.33.3"
@@ -956,16 +943,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "num-integer"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [
"autocfg 1.0.1",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.14"
@@ -1489,13 +1466,13 @@ name = "readability"
version = "0.1.4"
dependencies = [
"bitflags",
"chrono",
"html5ever",
"kuchiki",
"lazy_static",
"regex",
"serde_json",
"thiserror",
"time",
"url",
]
@@ -1963,14 +1940,21 @@ dependencies = [
[[package]]
name = "time"
version = "0.1.43"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
checksum = "99beeb0daeac2bd1e86ac2c21caddecb244b39a093594da1a661ec2060c7aedd"
dependencies = [
"itoa",
"libc",
"winapi",
"time-macros",
]
[[package]]
name = "time-macros"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25eb0ca3468fc0acc11828786797f6ef9aa1555e4a211a60d64cc8e4d1be47d6"
[[package]]
name = "tinytemplate"
version = "1.2.1"
@@ -12,12 +12,12 @@ edition = "2018"
[dependencies]
bitflags = "1.2"
chrono = "0.4"
html5ever = "0.25.1"
kuchiki = { git = "https://github.com/brave/kuchiki", branch = "speedreader" }
lazy_static = "1.4"
regex = "1"
serde_json = "1.0"
time = { version = "0.3.4", features = ["formatting", "macros", "parsing"] }
thiserror = "1.0.30"
url = "2.2"
@@ -1,5 +1,4 @@
use crate::{dom, nlp, scorer, util};
use chrono::DateTime;
use html5ever::parse_document;
use html5ever::tendril::TendrilSink;
use html5ever::tree_builder::NodeOrText;
@@ -11,6 +10,9 @@ use std::collections::{HashMap, HashSet};
use std::default::Default;
use std::io::Read;
use thiserror::Error;
use time::macros::format_description;
use time::OffsetDateTime;
use time::format_description::well_known::Rfc3339;
use url::Url;
use util::StringUtils;
@@ -72,7 +74,7 @@ pub struct Meta {
pub author: Option<String>,
pub description: Option<String>,
pub charset: Option<String>,
pub last_modified: Option<DateTime<chrono::offset::FixedOffset>>,
pub last_modified: Option<OffsetDateTime>,
}
impl Meta {
@@ -291,11 +293,11 @@ pub fn post_process(dom: &mut Sink, root: Handle, meta: &Meta) {
// Add in last modified datetime
if let Some(ref last_modified) = meta.last_modified {
let formatted = last_modified
.format("Updated %b. %d, %Y %H:%M %P")
.to_string();
let modified = dom::create_element_simple(dom, "p", "metadata date", Some(&formatted));
dom.append_before_sibling(&first_child, NodeOrText::AppendNode(modified));
let format = format_description!("Updated [month repr:short]. [day], [year] [hour repr:12]:[minute] [period]");
if let Some(formatted) = last_modified.format(format).ok() {
let modified = dom::create_element_simple(dom, "p", "metadata date", Some(&formatted));
dom.append_before_sibling(&first_child, NodeOrText::AppendNode(modified));
}
}
// Vertical split
@@ -477,7 +479,7 @@ fn try_parse_untyped_jsonld(content: &str, meta: &mut Meta) -> Result<(), JsonLd
.or_else(|| o.get("datePublished"))
.and_then(from_json_string)
{
meta.last_modified = chrono::DateTime::parse_from_rfc3339(&timestamp).ok();
meta.last_modified = OffsetDateTime::parse(&timestamp, &Rfc3339).ok();
}
}