1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! # zero-width-strip
//!
//! Strip zero-width and bidi-control Unicode characters from text.
//!
//! Zero-width characters (U+200B–U+200F, U+2060, U+FEFF, etc.) and bidi
//! overrides (U+202A–U+202E) are invisible in most renderers but are
//! preserved by most tokenizers, which makes them a clean payload
//! channel for prompt-injection attacks ("invisible instructions"
//! hidden inside otherwise plain text).
//!
//! This crate strips them.
//!
//! ## Example
//!
//! ```
//! use zero_width_strip::{strip, has_invisible};
//! let dirty = "hello\u{200B}\u{202E}world";
//! assert!(has_invisible(dirty));
//! assert_eq!(strip(dirty), "helloworld");
//! ```
/// True when the input contains any zero-width or bidi-override char.
/// Return a copy of `s` with every zero-width / bidi-override char
/// removed.
/// Strip into a caller-provided buffer (avoids an allocation).
/// Per-char test. The list covers:
/// - U+200B…U+200F (zero-width space, ZWNJ, ZWJ, LRM, RLM)
/// - U+202A…U+202E (LRE, RLE, PDF, LRO, RLO — bidi controls)
/// - U+2060…U+2064 (word joiner + invisible math operators)
/// - U+2066…U+2069 (LRI, RLI, FSI, PDI — bidi isolates)
/// - U+FEFF (BOM / zero-width no-break space)
/// - U+180E (Mongolian vowel separator)