summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2013-11-15 21:49:00 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2013-11-15 21:49:00 +0900
commit6037e1e2174e2cd391d4fbbdb8f9abc5398091e9 (patch)
tree01deca4895ebd24a2fc8d60f331ed48c03951bfa
parent43acf5c8a46ef21487f98693640e0a439a3ae2d8 (diff)
Ignore invalid UTF-8 sequences
-rwxr-xr-xfzf26
-rw-r--r--test/test_fzf.rb5
2 files changed, 27 insertions, 4 deletions
diff --git a/fzf b/fzf
index 978feaee..d226803a 100755
--- a/fzf
+++ b/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
diff --git a/test/test_fzf.rb b/test/test_fzf.rb
index 2ea3f5a9..681db5fb 100644
--- a/test/test_fzf.rb
+++ b/test/test_fzf.rb
@@ -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