Skip to content

Commit 659a9bd

Browse files
committed
fix string encoding issues
1 parent 0ce1447 commit 659a9bd

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

lib/ruby-debug-ide/commands/variables.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ def execute
7979
print_array(obj)
8080
elsif (obj.is_a?(Hash)) then
8181
print_hash(obj)
82+
elsif (obj.is_a?(String))
83+
print_string(obj)
8284
else
8385
print_element("variables") do
8486
# instance variables

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.17.beta14'
2+
IDE_VERSION='0.4.17.beta16'
33
end

lib/ruby-debug-ide/xml_printer.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)