MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / percent_encode_query

Function percent_encode_query

crates/openshell-core/src/secrets.rs:562–576  ·  view source on GitHub ↗

Percent-encode a string for safe use in URL query parameter values. Encodes all characters except unreserved characters (RFC 3986 Section 2.3): ALPHA / DIGIT / "-" / "." / "_" / "~"

(input: &str)

Source from the content-addressed store, hash-verified

560/// Encodes all characters except unreserved characters (RFC 3986 Section 2.3):
561/// ALPHA / DIGIT / "-" / "." / "_" / "~"
562fn percent_encode_query(input: &str) -> String {
563 let mut encoded = String::with_capacity(input.len());
564 for byte in input.bytes() {
565 match byte {
566 b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'.' | b'_' | b'~' => {
567 encoded.push(byte as char);
568 }
569 _ => {
570 use fmt::Write;
571 let _ = write!(encoded, "%{byte:02X}");
572 }
573 }
574 }
575 encoded
576}
577
578/// Percent-encode a string for safe use in URL path segments.
579///

Callers 1

Calls 2

lenMethod · 0.80
pushMethod · 0.80

Tested by 1