aboutsummaryrefslogtreecommitdiffstats
path: root/src/util/sanitize_uri.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-06-14 14:17:15 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-06-14 14:35:11 +0200
commit129ea34b18aaf7f5a01d404effbdc78cbbe67a74 (patch)
tree18157c97e6349c37d97861bcefe12b0c1c46724d /src/util/sanitize_uri.rs
parenta1ce43e428754084474a7ecf88ae6debf88b9164 (diff)
downloadmarkdown-rs-129ea34b18aaf7f5a01d404effbdc78cbbe67a74.tar.gz
markdown-rs-129ea34b18aaf7f5a01d404effbdc78cbbe67a74.tar.bz2
markdown-rs-129ea34b18aaf7f5a01d404effbdc78cbbe67a74.zip
Add examples to some docs
Diffstat (limited to 'src/util/sanitize_uri.rs')
-rw-r--r--src/util/sanitize_uri.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/util/sanitize_uri.rs b/src/util/sanitize_uri.rs
index 1dffc50..40e0f2c 100644
--- a/src/util/sanitize_uri.rs
+++ b/src/util/sanitize_uri.rs
@@ -17,6 +17,17 @@ use crate::util::encode::encode;
/// If the URL includes an unknown protocol (one not matched by `protocol`, such
/// as a dangerous example, `javascript:`), the value is ignored.
///
+/// ## Examples
+///
+/// ```rust ignore
+/// use micromark::util::sanitize_url::sanitize_url;
+///
+/// assert_eq!(sanitize_uri("javascript:alert(1)", &None), "javascript:alert(1)");
+/// assert_eq!(sanitize_uri("javascript:alert(1)", &Some(vec!["http", "https"])), "");
+/// assert_eq!(sanitize_uri("https://example.com", &Some(vec!["http", "https"])), "https://example.com");
+/// assert_eq!(sanitize_uri("https://a👍b.c/%20/%", &Some(vec!["http", "https"])), "https://a%F0%9F%91%8Db.c/%20/%25");
+/// ```
+///
/// ## References
///
/// * [`micromark-util-sanitize-uri` in `micromark`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-sanitize-uri)
@@ -61,6 +72,15 @@ pub fn sanitize_uri(value: &str, protocols: &Option<Vec<&str>>) -> String {
/// Encode unsafe characters with percent-encoding, skipping already encoded
/// sequences.
///
+/// ## Examples
+///
+/// ```rust ignore
+/// use micromark::util::sanitize_url::normalize_uri;
+///
+/// assert_eq!(sanitize_uri("https://example.com"), "https://example.com");
+/// assert_eq!(sanitize_uri("https://a👍b.c/%20/%"), "https://a%F0%9F%91%8Db.c/%20/%25");
+/// ```
+///
/// ## References
///
/// * [`micromark-util-sanitize-uri` in `micromark`](https://github.com/micromark/micromark/tree/main/packages/micromark-util-sanitize-uri)