Skip to main content

normalize_url_string

Function normalize_url_string 

Source
pub fn normalize_url_string(url_str: &str) -> Result<String, String>
Expand description

Normalize URL to prevent duplicates from trailing slashes, fragments, etc.

This function:

  • Removes ALL trailing slashes (including root path)
  • Removes fragments (#anchors)
  • Lowercases the scheme and host
  • Preserves query parameters

ยงExamples

use essence::utils::normalize_url_string;

assert_eq!(
    normalize_url_string("https://example.com/").unwrap(),
    "https://example.com"
);
assert_eq!(
    normalize_url_string("https://example.com/page/").unwrap(),
    "https://example.com/page"
);
assert_eq!(
    normalize_url_string("https://example.com/page#section").unwrap(),
    "https://example.com/page"
);