#urlencode #url #urldecode

urlencoding

A Rust library for doing URL percentage encoding

7 stable releases

2.1.3 Jul 21, 2023
2.1.2 Sep 2, 2022
2.1.0 Jul 18, 2021
1.3.3 May 15, 2021
0.2.0 Sep 16, 2016

#2008 in Encoding

Download history 1944851/week @ 2025-11-19 1435495/week @ 2025-11-26 1874261/week @ 2025-12-03 1965567/week @ 2025-12-10 1733411/week @ 2025-12-17 916803/week @ 2025-12-24 1265423/week @ 2025-12-31 2141138/week @ 2026-01-07 2133126/week @ 2026-01-14 2462115/week @ 2026-01-21 2491499/week @ 2026-01-28 2630083/week @ 2026-02-04 2573830/week @ 2026-02-11 2686247/week @ 2026-02-18 2840542/week @ 2026-02-25 2656832/week @ 2026-03-04

11,250,021 downloads per month
Used in 5,969 crates (1,814 directly)

MIT license

16KB
272 lines

urlencoding

Latest Version

A tiny Rust library for doing URL percentage encoding and decoding. It percent-encodes everything except alphanumerics and -, _, ., ~.

When decoding + is not treated as a space. Error recovery from incomplete percent-escapes follows the WHATWG URL standard.

Usage

To encode a string, do the following:

use urlencoding::encode;

let encoded = encode("This string will be URL encoded.");
println!("{}", encoded);
// This%20string%20will%20be%20URL%20encoded.

To decode a string, it's only slightly different:

use urlencoding::decode;

let decoded = decode("%F0%9F%91%BE%20Exterminate%21")?;
println!("{}", decoded);
// 👾 Exterminate!

To decode allowing arbitrary bytes and invalid UTF-8:

use urlencoding::decode_binary;

let binary = decode_binary(b"%F1%F2%F3%C0%C1%C2");
let decoded = String::from_utf8_lossy(&binary);

This library returns Cow to avoid allocating when decoding/encoding is not needed. Call .into_owned() on the Cow to get a Vec or String.

License

This project is licensed under the MIT license. For more information see the LICENSE file.

No runtime deps