Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix percent-encode doctests to actually test the functions #2891

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions core/http/src/raw_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,9 @@ impl RawStr {
/// # extern crate rocket;
/// use rocket::http::RawStr;
///
/// let raw_str = RawStr::new("Hello%21");
/// let decoded = raw_str.percent_decode();
/// assert_eq!(decoded, Ok("Hello!".into()));
/// ```
///
/// With an invalid string:
///
/// ```rust
/// # extern crate rocket;
/// use rocket::http::RawStr;
///
/// let bad_raw_str = RawStr::new("%FF");
/// assert!(bad_raw_str.percent_decode().is_err());
/// let raw_str = RawStr::new("Hello/goodbye");
/// let encoded = raw_str.percent_encode();
/// assert_eq!(encoded.as_str(), "Hello%2Fgoodbye");
/// ```
#[inline(always)]
pub fn percent_encode(&self) -> Cow<'_, RawStr> {
Expand All @@ -288,6 +278,7 @@ impl RawStr {
/// // Note: Rocket should never hand you a bad `&RawStr`.
/// let bytes = &[93, 12, 0, 13, 1];
/// let encoded = RawStr::percent_encode_bytes(&bytes[..]);
/// assert_eq!(encoded.as_str(), "]%0C%00%0D%01");
/// ```
#[inline(always)]
pub fn percent_encode_bytes(bytes: &[u8]) -> Cow<'_, RawStr> {
Expand Down
Loading