From 7d5cb9de49e496ef073f082d7206097292f5e9a6 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 12 Nov 2024 04:35:15 -0500 Subject: [PATCH] Cleanup URL tracking tests. (#5181) --- crates/utils/src/utils/validation.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/utils/src/utils/validation.rs b/crates/utils/src/utils/validation.rs index f8da6f609..4863b11b8 100644 --- a/crates/utils/src/utils/validation.rs +++ b/crates/utils/src/utils/validation.rs @@ -379,11 +379,14 @@ mod tests { use pretty_assertions::assert_eq; use url::Url; + const URL_WITH_TRACKING: &str = "https://example.com/path/123?utm_content=buffercf3b2&utm_medium=social&user+name=random+user&id=123"; + const URL_TRACKING_REMOVED: &str = "https://example.com/path/123?user+name=random+user&id=123"; + #[test] fn test_clean_url_params() -> LemmyResult<()> { - let url = Url::parse("https://example.com/path/123?utm_content=buffercf3b2&utm_medium=social&user+name=random+user&id=123")?; + let url = Url::parse(URL_WITH_TRACKING)?; let cleaned = clean_url(&url); - let expected = Url::parse("https://example.com/path/123?user+name=random+user&id=123")?; + let expected = Url::parse(URL_TRACKING_REMOVED)?; assert_eq!(expected.to_string(), cleaned.to_string()); let url = Url::parse("https://example.com/path/123")?; @@ -395,9 +398,9 @@ mod tests { #[test] fn test_clean_body() -> LemmyResult<()> { - let text = "[a link](https://example.com/path/123?utm_content=buffercf3b2&utm_medium=social&user+name=random+user&id=123)"; - let cleaned = clean_urls_in_text(text); - let expected = "[a link](https://example.com/path/123?user+name=random+user&id=123)"; + let text = format!("[a link]({URL_WITH_TRACKING})"); + let cleaned = clean_urls_in_text(&text); + let expected = format!("[a link]({URL_TRACKING_REMOVED})"); assert_eq!(expected.to_string(), cleaned.to_string()); let text = "[a link](https://example.com/path/123)";