Skip to content

Commit 293bd1e

Browse files
Merge pull request #89 from figma/shopify-sync/utf8-fix
[Shopify Sync] Fix failure dump with invalid UTF-8
2 parents 52f3b8d + c528fb1 commit 293bd1e

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)