Skip to content

Commit 8ffcfe9

Browse files
committed
RUBY-16838: "smart" way to get string representation of JBuilder.
Jbuilder.to_s returns nil instead of any reasonable string representation, to workaround it we use StringIO to get real representation.
1 parent 2b36de1 commit 8ffcfe9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/ruby-debug-ide/xml_printer.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'stringio'
12
require 'cgi'
23
require 'monitor'
34

@@ -180,7 +181,7 @@ def print_variable(name, value, kind)
180181
rescue StandardError => e
181182
print_debug "Unexpected exception \"%s\"\n%s", e.to_s, e.backtrace.join("\n")
182183
print("<variable name=\"%s\" kind=\"%s\" value=\"%s\"/>",
183-
CGI.escapeHTML(name), kind, CGI.escapeHTML(value.to_s))
184+
CGI.escapeHTML(name), kind, CGI.escapeHTML(safe_to_string(value)))
184185
end
185186

186187
def print_breakpoints(breakpoints)
@@ -379,6 +380,15 @@ def build_compact_value_attr(value, value_str)
379380
compact_value_str.nil? ? '' : "compactValue=\"#{CGI.escapeHTML(compact_value_str)}\""
380381
end
381382

383+
def safe_to_string(value)
384+
str = value.to_s
385+
return str unless str.nil?
386+
387+
string_io = StringIO.new
388+
string_io.write(value)
389+
string_io.string
390+
end
391+
382392
def build_value_attr(escaped_value_str)
383393
Debugger.rm_protocol_extensions ? '' : "value=\"#{escaped_value_str}\""
384394
end

0 commit comments

Comments
 (0)