@@ -127,6 +127,13 @@ def print_hash(hash)
127127 }
128128 end
129129 end
130+
131+ def print_string ( string )
132+ print_element ( "variables" ) do
133+ print_variable ( 'bytes' , string . bytes . to_a , 'instance' ) if string . respond_to? ( 'bytes' )
134+ print_variable ( 'encoding' , string . encoding , 'instance' ) if string . respond_to? ( 'encoding' )
135+ end
136+ end
130137
131138 def print_variable ( name , value , kind )
132139 name = name . to_s
@@ -141,13 +148,20 @@ def print_variable(name, value, kind)
141148 else
142149 value_str = "#{ value . class } (#{ value . size } element(s))"
143150 end
144- else
151+ elsif value . is_a? ( String )
152+ has_children = value . respond_to? ( 'bytes' ) || value . respond_to? ( 'encoding' )
153+ value_str = value
154+ else
145155 has_children = !value . instance_variables . empty? || !value . class . class_variables . empty?
146156 value_str = value . to_s || 'nil' rescue "<#to_s method raised exception: #$!>"
147157 unless value_str . is_a? ( String )
148158 value_str = "ERROR: #{ value . class } .to_s method returns #{ value_str . class } . Should return String."
149159 end
150160 end
161+
162+ if value_str . respond_to? ( 'encode' )
163+ value_str = value_str . encode ( "UTF-8" )
164+ end
151165 value_str = "[Binary Data]" if ( value_str . respond_to? ( 'is_binary_data?' ) && value_str . is_binary_data? )
152166 print ( "<variable name=\" %s\" kind=\" %s\" value=\" %s\" type=\" %s\" hasChildren=\" %s\" objectId=\" %#+x\" />" ,
153167 CGI . escapeHTML ( name ) , kind , CGI . escapeHTML ( value_str ) , value . class ,
@@ -256,12 +270,12 @@ def print_at_line(context, file, line)
256270 end
257271
258272 def print_exception ( exception , binding )
259- print_variables ( %w( error ) , 'exception' ) do | var |
273+ print_element ( "variables" ) do
260274 proxy = ExceptionProxy . new ( exception )
261275 InspectCommand . reference_result ( proxy )
262- proxy
276+ print_variable ( 'error' , proxy , 'exception' )
263277 end
264- rescue
278+ rescue Exception => e
265279 print "<processingException type=\" %s\" message=\" %s\" />" ,
266280 exception . class , CGI . escapeHTML ( exception . to_s )
267281 end
0 commit comments