Skip to content

Added RESERVED_ENCODE_SET & STRICT_ENCODE_SET & more detailed docs. #358

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

Closed
wants to merge 1 commit into from
Closed
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
30 changes: 29 additions & 1 deletion src/percent_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ macro_rules! define_encode_set {
}

/// This encode set is used for the path of cannot-be-a-base URLs.
/// Contains all of the ASCII control character range, DEL and the 8-bit range outside of ASCII –
/// that is, all byte values outsife of ASCII and all graphically unrepresentatble characters inside
/// of ASCII.
#[derive(Copy, Clone)]
#[allow(non_camel_case_types)]
pub struct SIMPLE_ENCODE_SET;
Expand All @@ -90,26 +93,51 @@ impl EncodeSet for SIMPLE_ENCODE_SET {

define_encode_set! {
/// This encode set is used in the URL parser for query strings.
/// Contains the `SIMPLE_ENCODE_SET` and additionally characters SPACE, `"`, `#`, `<` and `>`.
pub QUERY_ENCODE_SET = [SIMPLE_ENCODE_SET] | {' ', '"', '#', '<', '>'}
}

define_encode_set! {
/// This encode set is used for path components.
/// Contains the `QUERY_ENCODE_SET` and additionally characters `` ` ``, `?`, `{` and `}`.
pub DEFAULT_ENCODE_SET = [QUERY_ENCODE_SET] | {'`', '?', '{', '}'}
}

define_encode_set! {
/// This encode set is used for on '/'-separated path segment
/// This encode set is used for on `/`-separated path segment
/// Contains the `DEFAULT_ENCODE_SET` and additionally characters `%`, `/`.
pub PATH_SEGMENT_ENCODE_SET = [DEFAULT_ENCODE_SET] | {'%', '/'}
}

define_encode_set! {
/// This encode set is used for username and password.
/// Contains the `DEFAULT_ENCODE_SET` and additionally characters `/`, `:`, `;`, `=`, `@`, `[`,
/// `\`, `]`, `^` and `|`. Unlike `PATH_SEGMENT_ENCODE_SET`, doesn't contain character `%`.
pub USERINFO_ENCODE_SET = [DEFAULT_ENCODE_SET] | {
'/', ':', ';', '=', '@', '[', '\\', ']', '^', '|'
}
}

define_encode_set! {
/// This encode set encodes all the reserved URL delimiters defined in
/// [RFC3986](https://tools.ietf.org/html/rfc3986#section-2.2). Contains the `SIMPLE_ENCODE_SET`
/// and additionally characters `:`, `/`, `?`, `#`, `[`, `]`, `@`, `!`, `$`, `&`, `` ` ``, `(`,
/// `)`, `*`, `+`, `,`, `;`, `=`
pub RESERVED_ENCODE_SET = [SIMPLE_ENCODE_SET] | {
':', '/', '?', '#', '[', ']', '@', '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '='
}
}

define_encode_set! {
/// This encode set encodes all characters expect the unreserved characters defined in
/// [RFC3986](https://tools.ietf.org/html/rfc3986#section-2.3). Contains all expect characters
/// expect alphanumeric characters, `-`, `.`, `_` and `~`.
pub STRICT_ENCODE_SET = [SIMPLE_ENCODE_SET] | {
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '/', ':', ';', '<', '=',
'>', '?', '@', '[', '\\', ']', '^', '`', '{', '|', '}'
}
}

/// Return the percent-encoding of the given bytes.
///
/// This is unconditional, unlike `percent_encode()` which uses an encode set.
Expand Down