Skip to content

Commit b82e025

Browse files
author
Oleg Sukhodolsky
committed
Passing string value of a variable as text of sub-element
To be able to pass \n and other characters which can not be passed inside attribute. See http://youtrack.jetbrains.com/issue/RUBY-13641 for details.
1 parent 38b748e commit b82e025

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

lib/ruby-debug-ide/xml_printer.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ def print_variable(name, value, kind)
170170
end
171171
end
172172
value_str = "[Binary Data]" if (value_str.respond_to?('is_binary_data?') && value_str.is_binary_data?)
173-
print("<variable name=\"%s\" kind=\"%s\" value=\"%s\" type=\"%s\" hasChildren=\"%s\" objectId=\"%#+x\"/>",
173+
print("<variable name=\"%s\" kind=\"%s\" value=\"%s\" type=\"%s\" hasChildren=\"%s\" objectId=\"%#+x\">",
174174
CGI.escapeHTML(name), kind, CGI.escapeHTML(value_str), value.class,
175175
has_children, value.respond_to?(:object_id) ? value.object_id : value.id)
176+
print("<value><![CDATA[%s]]></value>", value_str)
177+
print('</variable>')
176178
end
177179

178180
def print_breakpoints(breakpoints)

test-base/readers.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def read_start_element(expected_element)
114114

115115
def read_text
116116
event = @parser.pull
117-
fail("expected \":text\" event, but got \"#{event.inspect}\"") unless event.text?
117+
fail("expected \":text\" event, but got \"#{event.inspect}\"") unless event.text? || event.cdata?
118118
event[0]
119119
end
120120

@@ -234,10 +234,25 @@ def read
234234
case event.event_type
235235
when :start_element
236236
check_event(:start_element, 'variable', event)
237-
ensure_end_element('variable')
237+
value_event = @parser.pull
238+
if value_event.event_type == :start_element
239+
check_event(:start_element, 'value', value_event)
240+
text_value = read_text
241+
ensure_end_element('value')
242+
ensure_end_element('variable')
243+
else
244+
text_value = event[1]['value']
245+
check_event(:end_element, 'variable', value_event)
246+
end
238247
variables << Variable.new(*Variable.members.map { |m|
239248
value = event[1][m.to_s]
240-
m.to_s == 'hasChildren' ? value == "true" : value
249+
if m.to_s == 'hasChildren'
250+
value == 'true'
251+
elsif m.to_s == 'value'
252+
text_value
253+
else
254+
value
255+
end
241256
})
242257
when :end_element
243258
check_event(:end_element, 'variables', event)

test-base/variables_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_variable_with_xml_content
2525
{:name => "stringA"},
2626
{:name => "testHashValue"})
2727
# will receive ''
28-
assert_xml("<start test=\"&\"/>", variables[0].value)
28+
assert_equal("<start test=\"&\"/>", variables[0].value)
2929
assert_local(variables[0])
3030
# the testHashValue contains an example, where the name consists of special
3131
# characters

0 commit comments

Comments
 (0)