fix: handle non-ascii characters command (#118)

closes #106

please read the conversation to understand this PR
tested on:
- Accented letters: é, ü, ñ
- Non-Latin scripts: Chinese characters (中文), Arabic (العربية)
- Symbols & Punctuation: ©, €, ™, —
- Emojis: 🚀, 😀

<img width="1312" height="976" alt="image"
src="https://github.com/user-attachments/assets/613f7e2b-3681-4a64-aeeb-e44f4276c8ee"
/>
This commit is contained in:
VERSE
2026-08-04 23:13:23 +07:00
committed by GitHub
parent 30619a8621
commit 75aa1fbe38
+18
View File
@@ -7,6 +7,7 @@ import (
"sort" "sort"
"strings" "strings"
"sync" "sync"
"unicode/utf8"
"github.com/versenilvis/fuzzy" "github.com/versenilvis/fuzzy"
"github.com/versenilvis/iris/integration/shell" "github.com/versenilvis/iris/integration/shell"
@@ -28,6 +29,7 @@ func RecordSessionCommand(cmd string) {
if cmd == "" { if cmd == "" {
return return
} }
cmd = sanitizeUTF8(cmd)
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
@@ -51,6 +53,21 @@ func init() {
idMapCache = make(map[string]int) idMapCache = make(map[string]int)
} }
func sanitizeUTF8(s string) string {
if utf8.ValidString(s) {
return s
}
var result strings.Builder
for _, r := range s {
if r == utf8.RuneError {
result.WriteRune('�')
} else {
result.WriteRune(r)
}
}
return result.String()
}
func SearchHistory(query string, aliases map[string]string) ([]HistResult, error) { func SearchHistory(query string, aliases map[string]string) ([]HistResult, error) {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
@@ -132,6 +149,7 @@ func SearchHistory(query string, aliases map[string]string) ([]HistResult, error
cmd = strings.TrimSpace(cmd) cmd = strings.TrimSpace(cmd)
if cmd != "" { if cmd != "" {
cmd = sanitizeUTF8(cmd)
allCmds = append(allCmds, cmd) allCmds = append(allCmds, cmd)
} }
} }