mirror of
https://github.com/chatmail/core.git
synced 2026-05-05 14:26:30 +03:00
fix: Correctly sanitize input everywhere (#5697)
Best reviewed commit-by-commit; the commit messages explain what is done.
This commit is contained in:
15
src/tools.rs
15
src/tools.rs
@@ -22,7 +22,7 @@ pub use std::time::SystemTime;
|
||||
use anyhow::{bail, Context as _, Result};
|
||||
use base64::Engine as _;
|
||||
use chrono::{Local, NaiveDateTime, NaiveTime, TimeZone};
|
||||
use deltachat_contact_tools::{strip_rtlo_characters, EmailAddress};
|
||||
use deltachat_contact_tools::EmailAddress;
|
||||
#[cfg(test)]
|
||||
pub use deltachat_time::SystemTimeTools as SystemTime;
|
||||
use futures::{StreamExt, TryStreamExt};
|
||||
@@ -511,13 +511,6 @@ pub fn parse_mailto(mailto_url: &str) -> Option<MailTo> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Sanitizes user input
|
||||
/// - strip newlines
|
||||
/// - strip malicious bidi characters
|
||||
pub(crate) fn improve_single_line_input(input: &str) -> String {
|
||||
strip_rtlo_characters(input.replace(['\n', '\r'], " ").trim())
|
||||
}
|
||||
|
||||
pub(crate) trait IsNoneOrEmpty<T> {
|
||||
/// Returns true if an Option does not contain a string
|
||||
/// or contains an empty string.
|
||||
@@ -1025,12 +1018,6 @@ DKIM Results: Passed=true";
|
||||
assert_eq!(h, 50);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_improve_single_line_input() {
|
||||
assert_eq!(improve_single_line_input("Hi\naiae "), "Hi aiae");
|
||||
assert_eq!(improve_single_line_input("\r\nahte\n\r"), "ahte");
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn test_maybe_warn_on_bad_time() {
|
||||
let t = TestContext::new().await;
|
||||
|
||||
Reference in New Issue
Block a user