Merge branch 'clippy_fix_1' into upgrade_deps_4

This commit is contained in:
Dessalines 2021-07-04 18:44:12 -04:00
commit b6b4e10c92
9 changed files with 85 additions and 50 deletions

90
Cargo.lock generated
View file

@ -70,9 +70,9 @@ dependencies = [
"log", "log",
"once_cell", "once_cell",
"parking_lot", "parking_lot",
"pin-project-lite 0.2.6", "pin-project-lite 0.2.7",
"smallvec", "smallvec",
"tokio 1.7.1", "tokio 1.8.0",
"tokio-util 0.6.7", "tokio-util 0.6.7",
] ]
@ -218,7 +218,7 @@ checksum = "bc7d7cd957c9ed92288a7c3c96af81fa5291f65247a76a34dac7b6af74e52ba0"
dependencies = [ dependencies = [
"actix-macros 0.2.1", "actix-macros 0.2.1",
"futures-core", "futures-core",
"tokio 1.7.1", "tokio 1.8.0",
] ]
[[package]] [[package]]
@ -548,7 +548,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"thiserror", "thiserror",
"tokio 1.7.1", "tokio 1.8.0",
"uuid", "uuid",
] ]
@ -567,7 +567,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"thiserror", "thiserror",
"tokio 1.7.1", "tokio 1.8.0",
"uuid", "uuid",
] ]
@ -1206,7 +1206,7 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ad9169582543d2cfe9961be1e9eaf4fc42f9aa3483f7c485717b8dde36466ea" checksum = "4ad9169582543d2cfe9961be1e9eaf4fc42f9aa3483f7c485717b8dde36466ea"
dependencies = [ dependencies = [
"hashbrown", "hashbrown 0.9.1",
] ]
[[package]] [[package]]
@ -1370,7 +1370,7 @@ dependencies = [
"futures-sink", "futures-sink",
"futures-task", "futures-task",
"memchr", "memchr",
"pin-project-lite 0.2.6", "pin-project-lite 0.2.7",
"pin-utils", "pin-utils",
"proc-macro-hack", "proc-macro-hack",
"proc-macro-nested", "proc-macro-nested",
@ -1477,7 +1477,7 @@ dependencies = [
"http", "http",
"indexmap", "indexmap",
"slab", "slab",
"tokio 1.7.1", "tokio 1.8.0",
"tokio-util 0.6.7", "tokio-util 0.6.7",
"tracing", "tracing",
] ]
@ -1491,6 +1491,12 @@ dependencies = [
"ahash", "ahash",
] ]
[[package]]
name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
[[package]] [[package]]
name = "heck" name = "heck"
version = "0.3.3" version = "0.3.3"
@ -1502,9 +1508,9 @@ dependencies = [
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.1.18" version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [ dependencies = [
"libc", "libc",
] ]
@ -1545,7 +1551,7 @@ checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9"
dependencies = [ dependencies = [
"bytes 1.0.1", "bytes 1.0.1",
"http", "http",
"pin-project-lite 0.2.6", "pin-project-lite 0.2.7",
] ]
[[package]] [[package]]
@ -1591,7 +1597,7 @@ dependencies = [
"reqwest", "reqwest",
"sha2", "sha2",
"thiserror", "thiserror",
"tokio 1.7.1", "tokio 1.8.0",
] ]
[[package]] [[package]]
@ -1628,9 +1634,9 @@ dependencies = [
"httparse", "httparse",
"httpdate", "httpdate",
"itoa", "itoa",
"pin-project-lite 0.2.6", "pin-project-lite 0.2.7",
"socket2 0.4.0", "socket2 0.4.0",
"tokio 1.7.1", "tokio 1.8.0",
"tower-service", "tower-service",
"tracing", "tracing",
"want", "want",
@ -1645,7 +1651,7 @@ dependencies = [
"bytes 1.0.1", "bytes 1.0.1",
"hyper", "hyper",
"native-tls", "native-tls",
"tokio 1.7.1", "tokio 1.8.0",
"tokio-native-tls", "tokio-native-tls",
] ]
@ -1687,12 +1693,12 @@ dependencies = [
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "1.6.2" version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"hashbrown", "hashbrown 0.11.2",
] ]
[[package]] [[package]]
@ -1840,7 +1846,7 @@ dependencies = [
"strum", "strum",
"strum_macros", "strum_macros",
"thiserror", "thiserror",
"tokio 1.7.1", "tokio 1.8.0",
"url", "url",
"uuid", "uuid",
] ]
@ -1903,7 +1909,7 @@ dependencies = [
"strum", "strum",
"strum_macros", "strum_macros",
"thiserror", "thiserror",
"tokio 1.7.1", "tokio 1.8.0",
"url", "url",
"uuid", "uuid",
] ]
@ -1950,7 +1956,7 @@ dependencies = [
"strum", "strum",
"strum_macros", "strum_macros",
"thiserror", "thiserror",
"tokio 1.7.1", "tokio 1.8.0",
"url", "url",
"uuid", "uuid",
] ]
@ -1995,7 +2001,7 @@ dependencies = [
"strum", "strum",
"strum_macros", "strum_macros",
"thiserror", "thiserror",
"tokio 1.7.1", "tokio 1.8.0",
"url", "url",
] ]
@ -2129,7 +2135,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"strum", "strum",
"tokio 1.7.1", "tokio 1.8.0",
"url", "url",
] ]
@ -2163,7 +2169,7 @@ dependencies = [
"strum", "strum",
"strum_macros", "strum_macros",
"thiserror", "thiserror",
"tokio 1.7.1", "tokio 1.8.0",
"url", "url",
] ]
@ -2189,7 +2195,7 @@ dependencies = [
"serde_json", "serde_json",
"strum", "strum",
"strum_macros", "strum_macros",
"tokio 1.7.1", "tokio 1.8.0",
] ]
[[package]] [[package]]
@ -2739,9 +2745,9 @@ checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777"
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.6" version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443"
[[package]] [[package]]
name = "pin-utils" name = "pin-utils"
@ -3056,11 +3062,11 @@ dependencies = [
"mime", "mime",
"native-tls", "native-tls",
"percent-encoding", "percent-encoding",
"pin-project-lite 0.2.6", "pin-project-lite 0.2.7",
"serde", "serde",
"serde_json", "serde_json",
"serde_urlencoded", "serde_urlencoded",
"tokio 1.7.1", "tokio 1.8.0",
"tokio-native-tls", "tokio-native-tls",
"url", "url",
"wasm-bindgen", "wasm-bindgen",
@ -3537,18 +3543,18 @@ dependencies = [
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "1.0.25" version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa6f76457f59514c7eeb4e59d891395fab0b2fd1d40723ae737d64153392e9c6" checksum = "93119e4feac1cbe6c798c34d3a53ea0026b0b1de6a120deef895137c0529bfe2"
dependencies = [ dependencies = [
"thiserror-impl", "thiserror-impl",
] ]
[[package]] [[package]]
name = "thiserror-impl" name = "thiserror-impl"
version = "1.0.25" version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a36768c0fbf1bb15eca10defa29526bda730a2376c2ab4393ccfa16fb1a318d" checksum = "060d69a0afe7796bf42e9e2ff91f5ee691fb15c53d38b4b62a9a53eb23164745"
dependencies = [ dependencies = [
"proc-macro2 1.0.27", "proc-macro2 1.0.27",
"quote 1.0.9", "quote 1.0.9",
@ -3662,9 +3668,9 @@ dependencies = [
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.7.1" version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fb2ed024293bb19f7a5dc54fe83bf86532a44c12a2bb8ba40d64a4509395ca2" checksum = "570c2eb13b3ab38208130eccd41be92520388791207fde783bda7c1e8ace28d4"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"bytes 1.0.1", "bytes 1.0.1",
@ -3673,7 +3679,7 @@ dependencies = [
"mio 0.7.13", "mio 0.7.13",
"once_cell", "once_cell",
"parking_lot", "parking_lot",
"pin-project-lite 0.2.6", "pin-project-lite 0.2.7",
"signal-hook-registry", "signal-hook-registry",
"winapi 0.3.9", "winapi 0.3.9",
] ]
@ -3685,7 +3691,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b"
dependencies = [ dependencies = [
"native-tls", "native-tls",
"tokio 1.7.1", "tokio 1.8.0",
] ]
[[package]] [[package]]
@ -3725,8 +3731,8 @@ dependencies = [
"futures-core", "futures-core",
"futures-sink", "futures-sink",
"log", "log",
"pin-project-lite 0.2.6", "pin-project-lite 0.2.7",
"tokio 1.7.1", "tokio 1.8.0",
] ]
[[package]] [[package]]
@ -3743,7 +3749,7 @@ checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"log", "log",
"pin-project-lite 0.2.6", "pin-project-lite 0.2.7",
"tracing-core", "tracing-core",
] ]
@ -3865,9 +3871,9 @@ dependencies = [
[[package]] [[package]]
name = "unicode-segmentation" name = "unicode-segmentation"
version = "1.7.1" version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"

View file

@ -2,6 +2,7 @@ limit_req_zone $binary_remote_addr zone=lemmy_ratelimit:10m rate=1r/s;
server { server {
listen 80; listen 80;
listen [::]:80;
server_name {{ domain }}; server_name {{ domain }};
location /.well-known/acme-challenge/ { location /.well-known/acme-challenge/ {
root /var/www/certbot; root /var/www/certbot;
@ -13,6 +14,7 @@ server {
server { server {
listen 443 ssl http2; listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name {{ domain }}; server_name {{ domain }};
ssl_certificate /etc/letsencrypt/live/{{domain}}/fullchain.pem; ssl_certificate /etc/letsencrypt/live/{{domain}}/fullchain.pem;

View file

@ -45,6 +45,6 @@ sha2 = "0.9.5"
async-trait = "0.1.50" async-trait = "0.1.50"
captcha = "0.0.8" captcha = "0.0.8"
anyhow = "1.0.41" anyhow = "1.0.41"
thiserror = "1.0.25" thiserror = "1.0.26"
background-jobs = "0.9.0" background-jobs = "0.9.0"
reqwest = { version = "0.11.4", features = ["json"] } reqwest = { version = "0.11.4", features = ["json"] }

View file

@ -39,6 +39,6 @@ uuid = { version = "0.8.2", features = ["serde", "v4"] }
sha2 = "0.9.5" sha2 = "0.9.5"
async-trait = "0.1.50" async-trait = "0.1.50"
anyhow = "1.0.41" anyhow = "1.0.41"
thiserror = "1.0.25" thiserror = "1.0.26"
background-jobs = "0.9.0" background-jobs = "0.9.0"
reqwest = { version = "0.11.4", features = ["json"] } reqwest = { version = "0.11.4", features = ["json"] }

View file

@ -13,7 +13,7 @@ use lemmy_db_schema::source::post::*;
use lemmy_db_views::post_view::PostView; use lemmy_db_views::post_view::PostView;
use lemmy_utils::{ use lemmy_utils::{
request::fetch_iframely_and_pictrs_data, request::fetch_iframely_and_pictrs_data,
utils::{check_slurs, check_slurs_opt, is_valid_post_title}, utils::{check_slurs, check_slurs_opt, clean_url_params, is_valid_post_title},
ApiError, ApiError,
ConnectionId, ConnectionId,
LemmyError, LemmyError,
@ -48,7 +48,7 @@ impl PerformCrud for CreatePost {
let post_form = PostForm { let post_form = PostForm {
name: data.name.trim().to_owned(), name: data.name.trim().to_owned(),
url: data_url.map(|u| u.to_owned().into()), url: data_url.map(|u| clean_url_params(u.to_owned()).into()),
body: data.body.to_owned(), body: data.body.to_owned(),
community_id: data.community_id, community_id: data.community_id,
creator_id: local_user_view.person.id, creator_id: local_user_view.person.id,

View file

@ -7,7 +7,7 @@ use lemmy_db_schema::{naive_now, source::post::*};
use lemmy_db_views::post_view::PostView; use lemmy_db_views::post_view::PostView;
use lemmy_utils::{ use lemmy_utils::{
request::fetch_iframely_and_pictrs_data, request::fetch_iframely_and_pictrs_data,
utils::{check_slurs_opt, is_valid_post_title}, utils::{check_slurs_opt, clean_url_params, is_valid_post_title},
ApiError, ApiError,
ConnectionId, ConnectionId,
LemmyError, LemmyError,
@ -59,7 +59,7 @@ impl PerformCrud for EditPost {
creator_id: orig_post.creator_id.to_owned(), creator_id: orig_post.creator_id.to_owned(),
community_id: orig_post.community_id, community_id: orig_post.community_id,
name: data.name.to_owned().unwrap_or(orig_post.name), name: data.name.to_owned().unwrap_or(orig_post.name),
url: data_url.map(|u| u.to_owned().into()), url: data_url.map(|u| clean_url_params(u.to_owned()).into()),
body: data.body.to_owned(), body: data.body.to_owned(),
nsfw: data.nsfw, nsfw: data.nsfw,
updated: Some(naive_now()), updated: Some(naive_now()),

View file

@ -46,7 +46,7 @@ uuid = { version = "0.8.2", features = ["serde", "v4"] }
sha2 = "0.9.5" sha2 = "0.9.5"
async-trait = "0.1.50" async-trait = "0.1.50"
anyhow = "1.0.41" anyhow = "1.0.41"
thiserror = "1.0.25" thiserror = "1.0.26"
background-jobs = "0.9.0" background-jobs = "0.9.0"
reqwest = { version = "0.11.4", features = ["json"] } reqwest = { version = "0.11.4", features = ["json"] }
backtrace = "0.3.60" backtrace = "0.3.60"

View file

@ -18,7 +18,7 @@ rand = "0.8.4"
percent-encoding = "2.1.0" percent-encoding = "2.1.0"
serde = { version = "1.0.126", features = ["derive"] } serde = { version = "1.0.126", features = ["derive"] }
serde_json = { version = "1.0.64", features = ["preserve_order"] } serde_json = { version = "1.0.64", features = ["preserve_order"] }
thiserror = "1.0.25" thiserror = "1.0.26"
comrak = { version = "0.10.1", default-features = false } comrak = { version = "0.10.1", default-features = false }
lazy_static = "1.4.0" lazy_static = "1.4.0"
openssl = "0.10.35" openssl = "0.10.35"

View file

@ -4,6 +4,7 @@ use chrono::{DateTime, FixedOffset, NaiveDateTime};
use itertools::Itertools; use itertools::Itertools;
use rand::{distributions::Alphanumeric, thread_rng, Rng}; use rand::{distributions::Alphanumeric, thread_rng, Rng};
use regex::{Regex, RegexBuilder}; use regex::{Regex, RegexBuilder};
use url::Url;
lazy_static! { lazy_static! {
static ref EMAIL_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9.!#$%&*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").expect("compile regex"); static ref EMAIL_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9.!#$%&*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").expect("compile regex");
@ -25,6 +26,8 @@ lazy_static! {
static ref VALID_COMMUNITY_NAME_REGEX: Regex = Regex::new(r"^[a-z0-9_]{3,20}$").expect("compile regex"); static ref VALID_COMMUNITY_NAME_REGEX: Regex = Regex::new(r"^[a-z0-9_]{3,20}$").expect("compile regex");
static ref VALID_POST_TITLE_REGEX: Regex = Regex::new(r".*\S.*").expect("compile regex"); static ref VALID_POST_TITLE_REGEX: Regex = Regex::new(r".*\S.*").expect("compile regex");
static ref VALID_MATRIX_ID_REGEX: Regex = Regex::new(r"^@[A-Za-z0-9._=-]+:[A-Za-z0-9.-]+\.[A-Za-z]{2,}$").expect("compile regex"); static ref VALID_MATRIX_ID_REGEX: Regex = Regex::new(r"^@[A-Za-z0-9._=-]+:[A-Za-z0-9.-]+\.[A-Za-z]{2,}$").expect("compile regex");
// taken from https://en.wikipedia.org/wiki/UTM_parameters
static ref CLEAN_URL_PARAMS_REGEX: Regex = Regex::new(r"^utm_source|utm_medium|utm_campaign|utm_term|utm_content|gclid|gclsrc|dclid|fbclid$").expect("compile regex");
} }
pub fn naive_from_unix(time: i64) -> NaiveDateTime { pub fn naive_from_unix(time: i64) -> NaiveDateTime {
@ -148,3 +151,27 @@ pub fn get_ip(conn_info: &ConnectionInfo) -> IpAddr {
.to_string(), .to_string(),
) )
} }
pub fn clean_url_params(mut url: Url) -> Url {
let new_query = url
.query_pairs()
.filter(|q| !CLEAN_URL_PARAMS_REGEX.is_match(&q.0))
.map(|q| format!("{}={}", q.0, q.1))
.join("&");
url.set_query(Some(&new_query));
url
}
#[cfg(test)]
mod tests {
use crate::utils::clean_url_params;
use url::Url;
#[test]
fn test_clean_url_params() {
let url = Url::parse("https://example.com/path/123?utm_content=buffercf3b2&utm_medium=social&username=randomuser&id=123").unwrap();
let cleaned = clean_url_params(url);
let expected = Url::parse("https://example.com/path/123?username=randomuser&id=123").unwrap();
assert_eq!(expected.to_string(), cleaned.to_string());
}
}