isVisible reports whether r is a visible Unicode character that should be preserved in prompt text. Each invisible range is documented with its Unicode name and rationale.
(r rune)
| 49 | // should be preserved in prompt text. Each invisible range is |
| 50 | // documented with its Unicode name and rationale. |
| 51 | func isVisible(r rune) bool { |
| 52 | switch { |
| 53 | // Soft hyphen — invisible in most renderers, used to hide |
| 54 | // content boundaries. |
| 55 | case r == 0x00AD: |
| 56 | return false |
| 57 | |
| 58 | // Combining grapheme joiner — invisible, no legitimate |
| 59 | // prompt use. |
| 60 | case r == 0x034F: |
| 61 | return false |
| 62 | |
| 63 | // Arabic letter mark — bidi control, invisible. |
| 64 | case r == 0x061C: |
| 65 | return false |
| 66 | |
| 67 | // Mongolian vowel separator — invisible spacing character. |
| 68 | case r == 0x180E: |
| 69 | return false |
| 70 | |
| 71 | // Zero-width space (U+200B). |
| 72 | case r == 0x200B: |
| 73 | return false |
| 74 | |
| 75 | // U+200C (ZWNJ) is deliberately NOT stripped. It is |
| 76 | // required for correct rendering of Persian, Urdu, and |
| 77 | // Kurdish scripts where it controls cursive joining. |
| 78 | // Stripping ZWS (U+200B) and ZWJ (U+200D) already breaks |
| 79 | // zero-width steganography encodings regardless of whether |
| 80 | // ZWNJ survives. |
| 81 | |
| 82 | // Zero-width joiner (U+200D) — also used in compound emoji, |
| 83 | // but actively exploited in steganography. See |
| 84 | // SanitizePromptText doc comment. |
| 85 | case r == 0x200D: |
| 86 | return false |
| 87 | |
| 88 | // Left-to-right mark (U+200E). |
| 89 | case r == 0x200E: |
| 90 | return false |
| 91 | |
| 92 | // Right-to-left mark (U+200F). |
| 93 | case r == 0x200F: |
| 94 | return false |
| 95 | |
| 96 | // Bidi embedding and override controls (U+202A–U+202E): |
| 97 | // LRE, RLE, PDF, LRO, RLO. |
| 98 | case r >= 0x202A && r <= 0x202E: |
| 99 | return false |
| 100 | |
| 101 | // Word joiner and invisible operators (U+2060–U+2064): |
| 102 | // word joiner, function application, invisible times, |
| 103 | // invisible separator, invisible plus. |
| 104 | case r >= 0x2060 && r <= 0x2064: |
| 105 | return false |
| 106 | |
| 107 | // Bidi isolate controls (U+2066–U+2069): |
| 108 | // LRI, RLI, FSI, PDI. |
no outgoing calls
no test coverage detected