mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-12-23 03:19:01 +00:00
Ignore invalid UTF-8 sequences
This commit is contained in:
parent
43acf5c8a4
commit
6037e1e217
26
fzf
26
fzf
@ -155,12 +155,27 @@ class FZF
|
||||
(arr[2] || 0)].pack('U*')
|
||||
end
|
||||
|
||||
if String.method_defined?(:each_char)
|
||||
def self.split str
|
||||
str.each_char.to_a
|
||||
end
|
||||
else
|
||||
def self.split str
|
||||
str.split('')
|
||||
end
|
||||
end
|
||||
|
||||
def self.nfc str, offsets = []
|
||||
ret = ''
|
||||
omap = []
|
||||
pend = []
|
||||
str.split(//).each_with_index do |c, idx|
|
||||
cp = c.ord
|
||||
split(str).each_with_index do |c, idx|
|
||||
cp =
|
||||
begin
|
||||
c.ord
|
||||
rescue Exception
|
||||
next
|
||||
end
|
||||
omap << ret.length
|
||||
unless pend.empty?
|
||||
if cp >= JUNGSUNG && cp < JUNGSUNG + JUNGSUNGS
|
||||
@ -221,9 +236,12 @@ class FZF
|
||||
def cursor_y; C.lines - 1; end
|
||||
def cprint str, col
|
||||
C.attron(col) do
|
||||
C.addstr str.gsub("\0", '')
|
||||
addstr_safe str
|
||||
end if str
|
||||
end
|
||||
def addstr_safe str
|
||||
C.addstr str.gsub("\0", '')
|
||||
end
|
||||
|
||||
def print_input
|
||||
C.setpos cursor_y, 0
|
||||
@ -320,7 +338,7 @@ class FZF
|
||||
cprint token, color(chosen ? :match! : :match, chosen)
|
||||
C.attron color(:chosen, true) if chosen
|
||||
else
|
||||
C.addstr token
|
||||
addstr_safe token
|
||||
end
|
||||
end
|
||||
C.attroff color(:chosen, true) if chosen
|
||||
|
@ -288,5 +288,10 @@ class TestFZF < MiniTest::Unit::TestCase
|
||||
assert_equal NFD, nfd
|
||||
end
|
||||
end
|
||||
|
||||
def test_split
|
||||
assert_equal ["a", "b", "c", "\xFF", "d", "e", "f"],
|
||||
FZF::UConv.split("abc\xFFdef")
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user