Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multibyte characters in fuzzyfinder.WithQuery() result in panic. #210

Open
AWtnb opened this issue Apr 15, 2024 · 0 comments
Open

Multibyte characters in fuzzyfinder.WithQuery() result in panic. #210

AWtnb opened this issue Apr 15, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@AWtnb
Copy link

AWtnb commented Apr 15, 2024

Multibyte characters in fuzzyfinder.WithQuery() result in panic.

fuzzyfinder.WithQuery() に日本語のようなマルチバイト文字が含まれているとpanicが発生するようです。

To reproduce

The following code will reproduce it.

下記のコードで再現されます。

package main

import (
	"fmt"

	"github.com/ktr0731/go-fuzzyfinder"
)

type Track struct {
	Name      string
	AlbumName string
	Artist    string
}

var tracks = []Track{
	{"foo", "album1", "artist1"},
	{"bar", "album1", "artist1"},
	{"foo", "album2", "artist1"},
	{"ほげ", "album2", "artist2"},
	{"ふが", "album3", "artist2"},
}

func main() {
	idx, err := fuzzyfinder.Find(tracks, func(i int) string {
		return tracks[i].Name
	}, fuzzyfinder.WithQuery("ほげ"))
	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("selected: %v\n", idx)
}

When I try to input any key, the following error message is output.

何かキー入力をしようとすると下記のエラーが出力されます。

However, once the cursor is moved to the beginning of line with Home or Ctrl-A, it works fine.

ただし、HomeCtrl-A でカーソルをいったん先頭に移動させれば問題なく操作できます。

panic: runtime error: index out of range [5] with length 2

goroutine 1 [running]:
github.com/ktr0731/go-fuzzyfinder.(*finder).readKey(0xc000176000, {0xc2c938, 0xc000070050})
        C:/Users/awtnb/go/pkg/mod/github.com/ktr0731/[email protected]/fuzzyfinder.go:506 +0x1217
github.com/ktr0731/go-fuzzyfinder.(*finder).find(0xc000176000, {0xbdbf60, 0xc0000083f0}, 0xc0d7d8, {0xc00011fef0, 0x1, 0x28fab239301?})
        C:/Users/awtnb/go/pkg/mod/github.com/ktr0731/[email protected]/fuzzyfinder.go:770 +0xb8d
github.com/ktr0731/go-fuzzyfinder.(*finder).Find(0xd348c0?, {0xbdbf60?, 0xc0000083f0?}, 0xc00011fea0?, {0xc00011fef0?, 0x18?, 0xbdefa0?})
        C:/Users/awtnb/go/pkg/mod/github.com/ktr0731/[email protected]/fuzzyfinder.go:823 +0x25
github.com/ktr0731/go-fuzzyfinder.Find({0xbdbf60, 0xc0000083f0}, 0x5?, {0xc00011fef0, 0x1, 0x1})
        C:/Users/awtnb/go/pkg/mod/github.com/ktr0731/[email protected]/fuzzyfinder.go:819 +0x5c
main.main()
        C:/Users/awtnb/Desktop/gofuzquerytest/main.go:24 +0x9b
exit status 2

Environment

  • OS: Windows11
  • Terminal: WezTerm, VSCode Integrated Terminal, cmd.exe
  • go-fuzzyfinder version: v0.8.0
@AWtnb AWtnb added the bug Something isn't working label Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant