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

Function build_canonical_path

crates/openshell-supervisor-network/src/l7/path.rs:267–298  ·  view source on GitHub ↗
(
    segments: &[Vec<u8>],
    _trailing_slash_hint: bool,
    opts: CanonicalizeOptions,
)

Source from the content-addressed store, hash-verified

265}
266
267fn build_canonical_path(
268 segments: &[Vec<u8>],
269 _trailing_slash_hint: bool,
270 opts: CanonicalizeOptions,
271) -> String {
272 let mut out = String::from("/");
273 for (idx, seg) in segments.iter().enumerate() {
274 if idx > 0 {
275 out.push('/');
276 }
277 let trimmed: &[u8] = if opts.strip_path_parameters {
278 match seg.iter().position(|&b| b == b';') {
279 Some(pos) => &seg[..pos],
280 None => seg,
281 }
282 } else {
283 seg
284 };
285 for &b in trimmed {
286 if b == ENCODED_SLASH_SENTINEL {
287 out.push_str("%2F");
288 } else if is_pchar_unreserved(b) {
289 out.push(b as char);
290 } else {
291 out.push('%');
292 out.push(upper_hex_nibble(b >> 4));
293 out.push(upper_hex_nibble(b & 0x0F));
294 }
295 }
296 }
297 out
298}
299
300fn is_pchar_unreserved(b: u8) -> bool {
301 // RFC 3986 pchar without the percent-encoded slot — i.e. bytes we emit

Callers 1

Calls 3

is_pchar_unreservedFunction · 0.85
upper_hex_nibbleFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected