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

Function percent_decode

crates/openshell-cli/src/oidc_auth.rs:309–328  ·  view source on GitHub ↗

Percent-decode a URL query parameter value.

(s: &str)

Source from the content-addressed store, hash-verified

307
308/// Percent-decode a URL query parameter value.
309fn percent_decode(s: &str) -> String {
310 let mut out = Vec::with_capacity(s.len());
311 let mut bytes = s.bytes();
312 while let Some(b) = bytes.next() {
313 if b == b'%' {
314 let hi = bytes.next().and_then(|b| char::from(b).to_digit(16));
315 let lo = bytes.next().and_then(|b| char::from(b).to_digit(16));
316 if let (Some(h), Some(l)) = (hi, lo) {
317 out.push(u8::try_from(h * 16 + l).unwrap_or(b'%'));
318 } else {
319 out.push(b'%');
320 }
321 } else if b == b'+' {
322 out.push(b' ');
323 } else {
324 out.push(b);
325 }
326 }
327 String::from_utf8(out).unwrap_or_else(|_| s.to_string())
328}
329
330/// Callback server state.
331struct CallbackState {

Callers 1

handle_oidc_callbackFunction · 0.70

Calls 3

lenMethod · 0.80
pushMethod · 0.80
nextMethod · 0.45

Tested by

no test coverage detected