#url #urlencode #escaping #codec #encode #decode #character-encoding

url-escape

This library is for encoding/escaping special characters in URLs and decoding/unescaping URLs as well

2 releases

0.1.1 Mar 19, 2022
0.1.0 Apr 21, 2021

#1215 in Encoding

Download history 3938/week @ 2023-12-13 3261/week @ 2023-12-20 2840/week @ 2023-12-27 4037/week @ 2024-01-03 4384/week @ 2024-01-10 4469/week @ 2024-01-17 5350/week @ 2024-01-24 7037/week @ 2024-01-31 6236/week @ 2024-02-07 5872/week @ 2024-02-14 7188/week @ 2024-02-21 5484/week @ 2024-02-28 6170/week @ 2024-03-06 6656/week @ 2024-03-13 5809/week @ 2024-03-20 4320/week @ 2024-03-27

23,976 downloads per month
Used in 51 crates (30 directly)

MIT license

18KB
219 lines

URL Escape

CI

This library is for encoding/escaping special characters in URLs and decoding/unescaping URLs as well.

Usage

Encoding

This crate provides some encode_* functions to encode URL text in different situations.

For example, to put a text to a fragment, use the encode_fragment function.

assert_eq!("a%20%3E%20b?", url_escape::encode_fragment("a > b?"));

The functions suffixed with _to_writer, _to_vec or _to_string are useful to generate URL text.

let mut url = String::from("https://");
assert_eq!("admin%40example.com", url_escape::encode_userinfo_to_string("admin@example.com", &mut url));
url.push_str("@127.0.0.1/");
assert_eq!("%E4%B8%AD%E6%96%87%E5%AD%97/eng/12%2034", url_escape::encode_path_to_string("中文字/eng/12 34", &mut url));
url.push('/');
assert_eq!(r"56%2F78", url_escape::encode_component_to_string("56/78", &mut url));
url.push('?');
assert_eq!(r"a=1&b=a%20b%20c", url_escape::encode_query_to_string("a=1&b=a b c", &mut url));

assert_eq!("https://admin%40example.com@127.0.0.1/%E4%B8%AD%E6%96%87%E5%AD%97/eng/12%2034/56%2F78?a=1&b=a%20b%20c", url);

Decoding

assert_eq!("中文字/eng/12 34", url_escape::decode("%E4%B8%AD%E6%96%87%E5%AD%97/eng/12%2034"));

Crates.io

https://crates.io/crates/url-escape

Documentation

https://docs.rs/url-escape

License

MIT

Dependencies

~14KB