Release 2.7.3.3: dark theme and Amnezia vpn:// import fixes.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package linknorm
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// SanitizeShareText strips BOM, bidi isolates and zero-width chars that break
|
||||
// scheme detection (common when pasting from messengers / Amnezia share).
|
||||
func SanitizeShareText(raw string) string {
|
||||
raw = strings.TrimPrefix(raw, "\ufeff")
|
||||
raw = strings.TrimSpace(raw)
|
||||
if raw == "" {
|
||||
return ""
|
||||
}
|
||||
var b strings.Builder
|
||||
b.Grow(len(raw))
|
||||
for _, r := range raw {
|
||||
switch r {
|
||||
case '\u200b', '\u200c', '\u200d', '\u2060', '\ufeff', // zero-width / BOM
|
||||
'\u2066', '\u2067', '\u2068', '\u2069', // LRI/RLI/FSI/PDI
|
||||
'\u200e', '\u200f', // LRM/RLM
|
||||
'\u202a', '\u202b', '\u202c', '\u202d', '\u202e': // embedding overrides
|
||||
continue
|
||||
}
|
||||
if r < 0x20 && r != '\n' && r != '\r' && r != '\t' {
|
||||
continue
|
||||
}
|
||||
if unicode.Is(unicode.Cf, r) { // other format controls
|
||||
continue
|
||||
}
|
||||
b.WriteRune(r)
|
||||
}
|
||||
return strings.TrimSpace(b.String())
|
||||
}
|
||||
Reference in New Issue
Block a user