Skip to main content

sanitize_uri

Function sanitize_uri 

Source
pub(crate) fn sanitize_uri(uri: &str) -> String
Expand description

Sanitizes a single URI string by ensuring it has a proper scheme.

Mirrors the logic from the iOS fixURLIfNeeded() method:

  1. If the URI is already a valid URL, return as-is.
  2. If prepending http:// yields a URL whose host is an IPv4 address, use http://.
  3. If the URI doesn’t already start with http, prepend https://.
  4. Otherwise, return as-is.