diff --git a/ChangeLog.md b/ChangeLog.md index 9e9911e..a80eaf3 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,8 @@ +## [0.4.23](https://github.com/ruby-debug/ruby-debug-ide/compare/v0.4.23.beta11...v0.4.23) + +* fixed problem with compact name for binary params (strings with invalid encoding) + [RUBY-15960](https://youtrack.jetbrains.com/issue/RUBY-15960) + ## [0.4.23.beta11](https://github.com/ruby-debug/ruby-debug-ide/compare/v0.4.23.beta10...v0.4.23.beta11) * adding breakpoint in non-existing file should not break debugger diff --git a/lib/ruby-debug-ide/version.rb b/lib/ruby-debug-ide/version.rb index d054ec8..f84dfc8 100755 --- a/lib/ruby-debug-ide/version.rb +++ b/lib/ruby-debug-ide/version.rb @@ -1,3 +1,3 @@ module Debugger - IDE_VERSION='0.4.23.beta11' + IDE_VERSION='0.4.23' end diff --git a/lib/ruby-debug-ide/xml_printer.rb b/lib/ruby-debug-ide/xml_printer.rb index a160162..e4660b0 100644 --- a/lib/ruby-debug-ide/xml_printer.rb +++ b/lib/ruby-debug-ide/xml_printer.rb @@ -91,8 +91,7 @@ def print_contexts(contexts) end def print_context(context) - current = 'current="yes"' if context.thread == Thread.current - print "", context.thnum, context.thread.status, Process.pid + print "", context.thnum, context.thread.status, Process.pid end def print_variables(vars, kind) @@ -147,30 +146,31 @@ def print_variable(name, value, kind) end if value.is_a?(Array) || value.is_a?(Hash) has_children = !value.empty? - unless has_children - value_str = "Empty #{value.class}" - else - size = value.size + if has_children + size = value.size value_str = "#{value.class} (#{value.size} element#{size > 1 ? "s" : "" })" + else + value_str = "Empty #{value.class}" end elsif value.is_a?(String) has_children = value.respond_to?('bytes') || value.respond_to?('encoding') value_str = value else has_children = !value.instance_variables.empty? || !value.class.class_variables.empty? - value_str = value.to_s || 'nil' rescue "<#to_s method raised exception: #$!>" + value_str = value.to_s || 'nil' rescue "<#to_s method raised exception: #{$!}>" unless value_str.is_a?(String) value_str = "ERROR: #{value.class}.to_s method returns #{value_str.class}. Should return String." end end if value_str.respond_to?('encode') + # noinspection RubyEmptyRescueBlockInspection begin value_str = value_str.encode("UTF-8") rescue - end + end end - value_str = "[Binary Data]" if (value_str.respond_to?('is_binary_data?') && value_str.is_binary_data?) + value_str = handle_binary_data(value_str) compact_value_str = build_compact_name(value_str, value) print("", CGI.escapeHTML(name), CGI.escapeHTML(compact_value_str), kind, CGI.escapeHTML(value_str), value.class, @@ -184,13 +184,13 @@ def build_compact_name(value_str, value) if value.is_a?(Array) slice = value[0..10] compact = slice.inspect - if (value.size != slice.size) + if value.size != slice.size compact = compact[0..compact.size-2] + ", ...]" end end if value.is_a?(Hash) - slice = value.sort_by { |k,v| k.to_s }[0..5] - compact = slice.map {|kv| "#{kv[0]}: #{kv[1]}"}.join(", ") + slice = value.sort_by { |k, _| k.to_s }[0..5] + compact = slice.map {|kv| "#{kv[0]}: #{handle_binary_data(kv[1])}"}.join(", ") compact = "{" + compact + (slice.size != value.size ? ", ..." : "") + "}" end compact @@ -255,7 +255,7 @@ def print_pp(value) def print_list(b, e, file, line) print "[%d, %d] in %s\n", b, e, file - if lines = Debugger.source_for(file) + if (lines = Debugger.source_for(file)) b.upto(e) do |n| if n > 0 && lines[n-1] if n == line @@ -266,7 +266,7 @@ def print_list(b, e, file, line) end end else - print "No sourcefile available for %s\n", file + print "No source-file available for %s\n", file end end @@ -280,7 +280,7 @@ def print_methods(methods) # Events - def print_breakpoint(n, breakpoint) + def print_breakpoint(_, breakpoint) print("", breakpoint.source, breakpoint.pos, Debugger.current_context.thnum) end @@ -302,7 +302,7 @@ def print_at_line(context, file, line) File.expand_path(file), line, context.thnum, context.stack_size end - def print_exception(exception, binding) + def print_exception(exception, _) print_element("variables") do proxy = ExceptionProxy.new(exception) InspectCommand.reference_result(proxy) @@ -343,6 +343,20 @@ def print(*params) @interface.print(*params) end + def handle_binary_data(value) + return '[Binary Data]' if (value.respond_to?('is_binary_data?') && value.is_binary_data?) + return '[Invalid encoding]' if (value.respond_to?('valid_encoding?') && !value.valid_encoding?) + value + end + + def current_thread_attr(context) + if context.thread == Thread.current + 'current="yes"' + else + '' + end + end + instance_methods.each do |m| if m.to_s.index('print_') == 0 protect m