Skip to content

Commit 8ac5c97

Browse files
committed
Merge pull request #64 from ruby-debug/binary-data-in-compact-name
Binary data in compact name
2 parents dedc61f + fbc485a commit 8ac5c97

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

lib/ruby-debug-ide/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Debugger
2-
IDE_VERSION='0.4.23.beta11'
2+
IDE_VERSION='0.4.23.rc1'
33
end

lib/ruby-debug-ide/xml_printer.rb

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ def print_contexts(contexts)
9191
end
9292

9393
def print_context(context)
94-
current = 'current="yes"' if context.thread == Thread.current
95-
print "<thread id=\"%s\" status=\"%s\" pid=\"%s\" #{current}/>", context.thnum, context.thread.status, Process.pid
94+
print "<thread id=\"%s\" status=\"%s\" pid=\"%s\" #{current_thread_attr(context)}/>", context.thnum, context.thread.status, Process.pid
9695
end
9796

9897
def print_variables(vars, kind)
@@ -147,30 +146,31 @@ def print_variable(name, value, kind)
147146
end
148147
if value.is_a?(Array) || value.is_a?(Hash)
149148
has_children = !value.empty?
150-
unless has_children
151-
value_str = "Empty #{value.class}"
152-
else
153-
size = value.size
149+
if has_children
150+
size = value.size
154151
value_str = "#{value.class} (#{value.size} element#{size > 1 ? "s" : "" })"
152+
else
153+
value_str = "Empty #{value.class}"
155154
end
156155
elsif value.is_a?(String)
157156
has_children = value.respond_to?('bytes') || value.respond_to?('encoding')
158157
value_str = value
159158
else
160159
has_children = !value.instance_variables.empty? || !value.class.class_variables.empty?
161-
value_str = value.to_s || 'nil' rescue "<#to_s method raised exception: #$!>"
160+
value_str = value.to_s || 'nil' rescue "<#to_s method raised exception: #{$!}>"
162161
unless value_str.is_a?(String)
163162
value_str = "ERROR: #{value.class}.to_s method returns #{value_str.class}. Should return String."
164163
end
165164
end
166165

167166
if value_str.respond_to?('encode')
167+
# noinspection RubyEmptyRescueBlockInspection
168168
begin
169169
value_str = value_str.encode("UTF-8")
170170
rescue
171-
end
171+
end
172172
end
173-
value_str = "[Binary Data]" if (value_str.respond_to?('is_binary_data?') && value_str.is_binary_data?)
173+
value_str = handle_binary_data(value_str)
174174
compact_value_str = build_compact_name(value_str, value)
175175
print("<variable name=\"%s\" compactValue=\"%s\" kind=\"%s\" value=\"%s\" type=\"%s\" hasChildren=\"%s\" objectId=\"%#+x\">",
176176
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)
184184
if value.is_a?(Array)
185185
slice = value[0..10]
186186
compact = slice.inspect
187-
if (value.size != slice.size)
187+
if value.size != slice.size
188188
compact = compact[0..compact.size-2] + ", ...]"
189189
end
190190
end
191191
if value.is_a?(Hash)
192-
slice = value.sort_by { |k,v| k.to_s }[0..5]
193-
compact = slice.map {|kv| "#{kv[0]}: #{kv[1]}"}.join(", ")
192+
slice = value.sort_by { |k, _| k.to_s }[0..5]
193+
compact = slice.map {|kv| "#{kv[0]}: #{handle_binary_data(kv[1])}"}.join(", ")
194194
compact = "{" + compact + (slice.size != value.size ? ", ..." : "") + "}"
195195
end
196196
compact
@@ -255,7 +255,7 @@ def print_pp(value)
255255

256256
def print_list(b, e, file, line)
257257
print "[%d, %d] in %s\n", b, e, file
258-
if lines = Debugger.source_for(file)
258+
if (lines = Debugger.source_for(file))
259259
b.upto(e) do |n|
260260
if n > 0 && lines[n-1]
261261
if n == line
@@ -266,7 +266,7 @@ def print_list(b, e, file, line)
266266
end
267267
end
268268
else
269-
print "No sourcefile available for %s\n", file
269+
print "No source-file available for %s\n", file
270270
end
271271
end
272272

@@ -280,7 +280,7 @@ def print_methods(methods)
280280

281281
# Events
282282

283-
def print_breakpoint(n, breakpoint)
283+
def print_breakpoint(_, breakpoint)
284284
print("<breakpoint file=\"%s\" line=\"%s\" threadId=\"%d\"/>",
285285
breakpoint.source, breakpoint.pos, Debugger.current_context.thnum)
286286
end
@@ -302,7 +302,7 @@ def print_at_line(context, file, line)
302302
File.expand_path(file), line, context.thnum, context.stack_size
303303
end
304304

305-
def print_exception(exception, binding)
305+
def print_exception(exception, _)
306306
print_element("variables") do
307307
proxy = ExceptionProxy.new(exception)
308308
InspectCommand.reference_result(proxy)
@@ -343,6 +343,20 @@ def print(*params)
343343
@interface.print(*params)
344344
end
345345

346+
def handle_binary_data(value)
347+
return '[Binary Data]' if (value.respond_to?('is_binary_data?') && value.is_binary_data?)
348+
return '[Invalid encoding]' if (value.respond_to?('valid_encoding?') && !value.valid_encoding?)
349+
value
350+
end
351+
352+
def current_thread_attr(context)
353+
if context.thread == Thread.current
354+
'current="yes"'
355+
else
356+
''
357+
end
358+
end
359+
346360
instance_methods.each do |m|
347361
if m.to_s.index('print_') == 0
348362
protect m

0 commit comments

Comments
 (0)