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

Function reject_control_chars

crates/openshell-server/src/grpc/validation.rs:72–84  ·  view source on GitHub ↗

Reject null bytes and newlines in a user-supplied value.

(value: &str, field_name: &str)

Source from the content-addressed store, hash-verified

70
71/// Reject null bytes and newlines in a user-supplied value.
72pub(super) fn reject_control_chars(value: &str, field_name: &str) -> Result<(), Status> {
73 if value.bytes().any(|b| b == 0) {
74 return Err(Status::invalid_argument(format!(
75 "{field_name} contains null bytes"
76 )));
77 }
78 if value.bytes().any(|b| b == b'\n' || b == b'\r') {
79 return Err(Status::invalid_argument(format!(
80 "{field_name} contains newline or carriage return characters"
81 )));
82 }
83 Ok(())
84}
85
86// ---------------------------------------------------------------------------
87// Sandbox spec validation

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected