sanitize_identifier

Function sanitize_identifier 

Source
pub fn sanitize_identifier(identifier: &str) -> String
Expand description

Sanitize an identifier (table name, schema name, etc.) for display

Removes control characters and limits length to prevent log injection attacks and ensure readable error messages.

Note: This is for display purposes only. For SQL safety, use parameterized queries instead.

§Arguments

  • identifier - The identifier to sanitize (table name, schema name, etc.)

§Returns

Sanitized string with control characters removed and length limited to 100 chars.

§Examples

assert_eq!(sanitize_identifier("normal_table"), "normal_table");
assert_eq!(sanitize_identifier("table\x00name"), "tablename");
assert_eq!(sanitize_identifier("table\nname"), "tablename");

// Length limit
let long_name = "a".repeat(200);
assert_eq!(sanitize_identifier(&long_name).len(), 100);