Skip to main content

quote_string

Function quote_string 

Source
pub fn quote_string(s: &str) -> Result<String>
Expand description

Returns s wrapped in GQL single quotes, with backslashes and single quotes properly escaped.

Escape order matches the Go reference: backslash first (\\\), then single quotes (' becomes two single quotes '').

ASCII control characters (< 0x20 or 0x7F) are rejected rather than escaped; this is intentional because quote_string is meant for user-supplied data where control characters are almost always an error (injection risk).

§Errors

Returns Error::Validation if s contains ASCII control characters.

§Example

use geode_client::quote_string;

assert_eq!(quote_string("hello").unwrap(), "'hello'");
assert_eq!(quote_string("O'Brien").unwrap(), "'O''Brien'");
assert_eq!(quote_string("a\\b").unwrap(), "'a\\\\b'");
assert!(quote_string("bad\nline").is_err());