Skip to content

Commit 9dffc3e

Browse files
author
Anirudh Ramanathan
committed
Use innerhtml instead of getting text which doesn't work when we have <![CDATA[..]> sections inside the failure/error tags
1 parent 85bb525 commit 9dffc3e

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

ruby/bin/annotate

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
11
#!/usr/bin/env ruby
22

33
require 'rexml/document'
4+
require "rexml/element"
5+
6+
# Adapted from https://stackoverflow.com/a/25888239/759019
7+
class REXML::Element
8+
def innerHTML=(xml)
9+
require "rexml/document"
10+
self.to_a.each do |e|
11+
self.delete e
12+
end
13+
d = REXML::Document.new "<root>#{xml}</root>"
14+
d.root.to_a.each do |e|
15+
case e
16+
when REXML::Text
17+
self.add_text e
18+
when REXML::Element
19+
self.add_element e
20+
else
21+
puts "ERROR"
22+
end
23+
end
24+
xml
25+
end
26+
def inner_html
27+
ret = ''
28+
self.to_a.each do |e|
29+
ret += e.to_s
30+
end
31+
ret
32+
end
33+
end
434

535
# Reads a list of junit files and returns a nice Buildkite build annotation on
636
# STDOUT that summarizes any failures.
@@ -33,10 +63,10 @@ junit_report_files.sort.each do |file|
3363
name = testcase.attributes['name'].to_s
3464
failed_test = testcase.attributes[failure_format].to_s
3565
testcase.elements.each("failure") do |failure|
36-
failures << Failure.new(name, failed_test, failure.text, job, :failure)
66+
failures << Failure.new(name, failed_test, failure.inner_html, job, :failure)
3767
end
3868
testcase.elements.each("error") do |error|
39-
failures << Failure.new(name, failed_test, error.text, job, :error)
69+
failures << Failure.new(name, failed_test, error.inner_html, job, :error)
4070
end
4171
end
4272
end

0 commit comments

Comments
 (0)