clearurls
A Rust library that strips tracking parameters and redirects from URLs using the crowd-sourced ClearURLs rules.
Repository Health
Technical Analysis
clearurls brings the widely used ClearURLs rule set to Rust, letting you remove tracking parameters, referral tags, and redirect wrappers from URLs with a single call. The crate embeds the community-maintained rules so cleaning works out of the box, and exposes a small UrlCleaner API that returns a sanitized URL string.
Designed to be lightweight and portable, the core logic works without the standard library, making it suitable for embedded and WASM targets. Optional features add file-based rule loading and integration with linkify and markdown-it for cleaning links found inside free-form or Markdown text.
What You Get
- A simple UrlCleaner API that returns a cleaned URL string
- The full ClearURLs rule set embedded for offline, zero-config use
- no_std compatibility so the core works on embedded and WASM targets
- Optional file-based rule loading behind the std feature
- Optional linkify and markdown-it integration to clean links inside text
Common Use Cases
- Removing utm_* and other tracking parameters before storing or sharing URLs
- Sanitizing links submitted by users in a forum, chat, or feed reader
- Unwrapping redirect and referral URLs to recover the real destination
Under The Hood
Architecture - The public surface (src/lib.rs) is a UrlCleaner built from embedded or file-loaded rules; src/rules.rs deserializes the ClearURLs data.minify.json provider definitions into compiled regex matchers, and cleaning applies each matching provider’s rules to strip query parameters and unwrap redirects on a parsed url::Url. Custom deserialization helpers in src/deserialize_utils.rs adapt the JSON rule schema.
Tech Stack - Pure Rust (edition 2021, MSRV 1.65) built on serde/serde_json for rule parsing, regex for provider and parameter matching, url and percent-encoding for URL handling — all configured with default-features off so the crate stays no_std-capable. Optional linkify and markdown-it dependencies gate the text-integration features.
Code Quality - The tests/ directory holds focused suites for single-URL cleaning, linkify, and markdown integration, with cases borrowed from established URL-cleaning projects, giving reasonable behavioral coverage for a small crate. A clippy.toml signals lint discipline and the code is organized into small, single-responsibility modules.
API Design - Getting started is a two-line path: UrlCleaner::from_embedded_rules() then clear_single_url_str(...), both returning Result for explicit error handling. Feature flags keep the default build lean while letting advanced users opt into std file loading or in-text link cleaning, a clean and discoverable API for a narrow, well-scoped problem.