Skip to main content

sanitize_token

Function sanitize_token 

Source
fn sanitize_token(raw: &str) -> String
Expand description

Converts arbitrary identity text into a single NATS subject token.

Leading and trailing whitespace is trimmed. ASCII letters and digits are lowercased, - and _ are kept, and whitespace, . and / become -. Every other character is dropped. Leading and trailing - are then stripped. This keeps . (the subject separator) and the wildcards * and > out of the token.

§Arguments

  • raw - Identity text such as a site ID, box ID or LabJack name.

§Returns

The sanitized token, or unknown if nothing usable remains.

§Examples

sanitize_token("I69 MU1")   -> "i69-mu1"
sanitize_token("site.a/b")  -> "site-a-b"
sanitize_token(" *> ")      -> "unknown"