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

#1405 in Encoding

Download history 828946/week @ 2025-01-18 866734/week @ 2025-01-25 966795/week @ 2025-02-01 1163707/week @ 2025-02-08 1271586/week @ 2025-02-15 1306578/week @ 2025-02-22 1319442/week @ 2025-03-01 1321677/week @ 2025-03-08 1291742/week @ 2025-03-15 1421352/week @ 2025-03-22 1415063/week @ 2025-03-29 1498095/week @ 2025-04-05 1237440/week @ 2025-04-12 1187618/week @ 2025-04-19 1092725/week @ 2025-04-26 1024666/week @ 2025-05-03

4,786,821 downloads per month
Used in 3,256 crates (775 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