#url #percent #escape #urlencode #urldecode

urlencoding

A Rust library for doing URL percentage encoding

10 releases (stable)

2.1.0 Jul 18, 2021
2.0.0 Jul 12, 2021
2.0.0-alpha.1 May 14, 2021
1.3.3 May 15, 2021
0.1.1 Sep 15, 2016

#11 in Encoding

Download history 41886/week @ 2021-08-08 42893/week @ 2021-08-15 40851/week @ 2021-08-22 44492/week @ 2021-08-29 44815/week @ 2021-09-05 52288/week @ 2021-09-12 51574/week @ 2021-09-19 52513/week @ 2021-09-26 47124/week @ 2021-10-03 47693/week @ 2021-10-10 50439/week @ 2021-10-17 51079/week @ 2021-10-24 45230/week @ 2021-10-31 50598/week @ 2021-11-07 50509/week @ 2021-11-14 44388/week @ 2021-11-21

125,956 downloads per month
Used in 287 crates (120 directly)

MIT license

14KB
241 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