From 3a8e39b3a12c2d495fe404b729fdd609a1cf2ae2 Mon Sep 17 00:00:00 2001 From: tompng Date: Sat, 25 Oct 2025 16:21:17 +0900 Subject: [PATCH] Fix candidates select to handle encoding error when encoding-incompatible method name exists --- lib/repl_type_completor/result.rb | 6 +++++- test/repl_type_completor/test_repl_type_completor.rb | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/repl_type_completor/result.rb b/lib/repl_type_completor/result.rb index 134b03b..c58a01a 100644 --- a/lib/repl_type_completor/result.rb +++ b/lib/repl_type_completor/result.rb @@ -72,7 +72,11 @@ def completion_candidates else [] end - candidates.select { _1.start_with?(name) }.map { _1[name.size..] } + + candidates.filter_map do + _1[name.size..] if _1.start_with?(name) + rescue EncodingError + end rescue Exception => e ReplTypeCompletor.handle_exception(e) [] diff --git a/test/repl_type_completor/test_repl_type_completor.rb b/test/repl_type_completor/test_repl_type_completor.rb index 1c06c6d..e67c937 100644 --- a/test/repl_type_completor/test_repl_type_completor.rb +++ b/test/repl_type_completor/test_repl_type_completor.rb @@ -218,6 +218,14 @@ def b.foobaz; end assert_completion('arr.sample.sample.sample.foo', binding: bind, include: 'bar', exclude: 'baz') end + def test_incompatible_encoding_method + a = Object.new + a.define_singleton_method(:abc){} + a.define_singleton_method("\u{3042}".encode('UTF-16')){} + bind = binding + assert_completion('a.a', include: 'bc', binding: bind) + end + DEPRECATED_CONST = 1 deprecate_constant :DEPRECATED_CONST def test_deprecated_const_without_warning