@@ -91,8 +91,7 @@ def print_contexts(contexts)
91
91
end
92
92
93
93
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
96
95
end
97
96
98
97
def print_variables ( vars , kind )
@@ -147,30 +146,31 @@ def print_variable(name, value, kind)
147
146
end
148
147
if value . is_a? ( Array ) || value . is_a? ( Hash )
149
148
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
154
151
value_str = "#{ value . class } (#{ value . size } element#{ size > 1 ? "s" : "" } )"
152
+ else
153
+ value_str = "Empty #{ value . class } "
155
154
end
156
155
elsif value . is_a? ( String )
157
156
has_children = value . respond_to? ( 'bytes' ) || value . respond_to? ( 'encoding' )
158
157
value_str = value
159
158
else
160
159
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: #{ $! } >"
162
161
unless value_str . is_a? ( String )
163
162
value_str = "ERROR: #{ value . class } .to_s method returns #{ value_str . class } . Should return String."
164
163
end
165
164
end
166
165
167
166
if value_str . respond_to? ( 'encode' )
167
+ # noinspection RubyEmptyRescueBlockInspection
168
168
begin
169
169
value_str = value_str . encode ( "UTF-8" )
170
170
rescue
171
- end
171
+ end
172
172
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 )
174
174
compact_value_str = build_compact_name ( value_str , value )
175
175
print ( "<variable name=\" %s\" compactValue=\" %s\" kind=\" %s\" value=\" %s\" type=\" %s\" hasChildren=\" %s\" objectId=\" %#+x\" >" ,
176
176
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)
184
184
if value . is_a? ( Array )
185
185
slice = value [ 0 ..10 ]
186
186
compact = slice . inspect
187
- if ( value . size != slice . size )
187
+ if value . size != slice . size
188
188
compact = compact [ 0 ..compact . size -2 ] + ", ...]"
189
189
end
190
190
end
191
191
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 ( ", " )
194
194
compact = "{" + compact + ( slice . size != value . size ? ", ..." : "" ) + "}"
195
195
end
196
196
compact
@@ -255,7 +255,7 @@ def print_pp(value)
255
255
256
256
def print_list ( b , e , file , line )
257
257
print "[%d, %d] in %s\n " , b , e , file
258
- if lines = Debugger . source_for ( file )
258
+ if ( lines = Debugger . source_for ( file ) )
259
259
b . upto ( e ) do |n |
260
260
if n > 0 && lines [ n -1 ]
261
261
if n == line
@@ -266,7 +266,7 @@ def print_list(b, e, file, line)
266
266
end
267
267
end
268
268
else
269
- print "No sourcefile available for %s\n " , file
269
+ print "No source-file available for %s\n " , file
270
270
end
271
271
end
272
272
@@ -280,7 +280,7 @@ def print_methods(methods)
280
280
281
281
# Events
282
282
283
- def print_breakpoint ( n , breakpoint )
283
+ def print_breakpoint ( _ , breakpoint )
284
284
print ( "<breakpoint file=\" %s\" line=\" %s\" threadId=\" %d\" />" ,
285
285
breakpoint . source , breakpoint . pos , Debugger . current_context . thnum )
286
286
end
@@ -302,7 +302,7 @@ def print_at_line(context, file, line)
302
302
File . expand_path ( file ) , line , context . thnum , context . stack_size
303
303
end
304
304
305
- def print_exception ( exception , binding )
305
+ def print_exception ( exception , _ )
306
306
print_element ( "variables" ) do
307
307
proxy = ExceptionProxy . new ( exception )
308
308
InspectCommand . reference_result ( proxy )
@@ -343,6 +343,20 @@ def print(*params)
343
343
@interface . print ( *params )
344
344
end
345
345
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
+
346
360
instance_methods . each do |m |
347
361
if m . to_s . index ( 'print_' ) == 0
348
362
protect m
0 commit comments