-
-
Notifications
You must be signed in to change notification settings - Fork 176
Clean links - remove superfluous tracking elements from URLs #460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! Thanks for the PR - a few comments.
} | ||
|
||
// Remove tracking query params | ||
static URL_CLEANER: Lazy<Mutex<UrlCleaner>> = Lazy::new(|| Mutex::new(UrlCleaner::from_embedded_rules().expect("Failed to initialize UrlCleaner"))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we use a mutex? clear_single_url_str
doesn't take &mut str
as a parameter, so we don't need mutual exclusion, we should be able to get away with something like an Arc
- this also improves performance as we don't have unnecessary lock contention. A static is a good idea though - so we only construct the UrlCleaner
once without constantly reparsing rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
pub fn clean_url(url: String) -> String { | ||
let is_external_url = match Url::parse(url.as_str()) { | ||
Ok(parsed_url) => parsed_url.domain().is_some(), | ||
_ => false, | ||
}; | ||
let mut cleaned_url = url.clone(); | ||
if is_external_url { | ||
let cleaner = URL_CLEANER.lock().unwrap(); | ||
cleaned_url = cleaner.clear_single_url_str(cleaned_url.as_str()).expect("Unable to clean the URL.").as_ref().to_owned(); | ||
} | ||
cleaned_url | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should handle the failed cases better - specifically (once you remove the mutex) the expect for the UrlCleaner::clear_single_url_str
call should fallback to the input, instead of panicking. This shouldn't happen since the clearurls::Error
enum is pretty small (and default embedded rules presumably exclude most of them); but a malformed URL is very likely.
"ఴӅβØØҞÉဏႢձĬ༧ȒʯऌԔӵ୮༏", | ||
"ਧՊΥÀÃǎƱГ۸ඣമĖฤ႙ʟาúໜϾௐɥঀĜໃહཞઠѫҲɂఙ࿔DzઉƲӟӻĻฅΜδ໖ԜǗဖငƦơ৶Ą௩ԹʛใЛʃශаΏ", | ||
"ਧԩΥÀÃΊ౭൩ඔႠϼҭöҪƸռઇԾॐნɔາǒՍҰच௨ಖມŃЉŐདƦ๙ϩএఠȝഽйʮჯඒϰळՋ௮ສ৵ऎΦѧਹಧଟƙŃ३î༦ŌပղयƟแҜ།", | ||
"ਧӐΥºÃΦĴгౡୡϤҚԷŽဎՐΧΣೡຽဒ೨ʛĽତ๘Ӓǹভµɾ൦ॴцৱ௬చΣҭжҭȱȾཊజĊȔ௸७ƘȂј۰ȥėǨԯၻíႽਈႴ۹ଆ", | ||
"ਧҫടºÃǒɣυໃਣөŕǁజ८ௐɪDžઘႴ౨ඛႻຫǪၼդɍ৪Êѕ୶ʭѹŪҚຊೱѰງიŠСঌາඌĨğਜડ࿅ଠಲೱҋŇƞਭăʁझшȖǾཔ௧ந۞ສÚ", | ||
"ਧҫടºÃǒɿဧϯljഔค๖۞ԆНȦ൨ĭ྅ҤƍตཧႯƅशञঊମਇȕමзқଽijჰଐՋບӎՓஶཕ૭ଛกήऋĜɀಱӔԩझԩîဓŒԬũլಙટщೞຝ৪༎", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should leave the old configs there, so that we can confirm backwards compatibility is preserved.
#[revision(start = 1)] | ||
pub clean_urls: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please review revision
docs to handle this - specifically, you'll want to increment the upper level struct's revision to 2, set the start for clean_urls
to 2, and read the docs on how you'll handle reverse compatibility (default to off).
if subscriptions.is_some() { | ||
let sub_list: Vec<String> = subscriptions.expect("Subscriptions").split('+').map(str::to_string).collect(); | ||
if let Some(subscriptions) = subscriptions { | ||
let sub_list: Vec<String> = subscriptions.split('+').map(str::to_string).collect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can leave this unpatched (as well as :213-214) - I'd rather atomic PR's and fixed this in main
- ignore the CI/CD checks
For the last couple of months I've been running a modified version of Redlib on my personal “instance.”
I essentially added a new option to the settings that make Redlib remove common tracking elements from the links posted to Reddit. A small privacy gain when we don't have browser extensions to do this job.
Since it is running smoothly, I think this could benefit all Redlib users. So here's the PR; feel free to dismiss or suggest improvements.