Skip to content

Commit 785a342

Browse files
authored
Merge pull request #365 from skipkayhil/hm-muozxolwvrrwqyzr
Fix failure file dump when output has invalid UTF8
2 parents 3a5ac9d + ed4ae26 commit 785a342

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

ruby/lib/minitest/queue/failure_formatter.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ def initialize(test)
1313
end
1414

1515
def to_s
16-
[
17-
header,
18-
body,
19-
"\n"
20-
].flatten.compact.join("\n")
16+
s = +"#{header}\n#{body}\n\n"
17+
s.encode!(Encoding::UTF_8, invalid: :replace, undef: :replace)
18+
s
2119
end
2220

2321
def to_h
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
require 'test_helper'
4+
5+
module Minitest::Queue
6+
class FailureFormatterTest < Minitest::Test
7+
include ReporterTestHelper
8+
9+
def test_failure_formatter_to_h_can_be_json_dumped
10+
test = result('test_json', failure: "\xD6".b)
11+
12+
formatter = FailureFormatter.new(test)
13+
14+
assert JSON.dump(formatter.to_h)
15+
end
16+
end
17+
end

0 commit comments

Comments
 (0)