Skip to content

Commit 4b41664

Browse files
committed
Read generated files in binary mode
So that fixes crash with "invalid byte sequence in US-ASCII" on ci.rvm.jp and some RubyCIs.
1 parent 987c609 commit 4b41664

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

test/rdoc/test_rdoc_generator_darkfish.rb

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,13 @@ def test_generate
107107

108108
encoding = Regexp.escape Encoding::UTF_8.name
109109

110-
assert_match %r%<meta charset="#{encoding}">%, File.read('index.html')
111-
assert_match %r%<meta charset="#{encoding}">%, File.read('Object.html')
110+
assert_match %r%<meta charset="#{encoding}">%, File.binread('index.html')
111+
assert_match %r%<meta charset="#{encoding}">%, File.binread('Object.html')
112112

113-
refute_match(/Ignored/, File.read('index.html'))
114-
summary = File.read('index.html')[%r[<summary.*Klass\.html.*</summary>.*</details>]m]
113+
refute_match(/Ignored/, File.binread('index.html'))
114+
summary = File.binread('index.html')[%r[<summary.*Klass\.html.*</summary>.*</details>]m]
115115
assert_match(%r[Klass/Inner\.html".*>Inner<], summary)
116-
omit 'The following line crashes with "invalid byte sequence in US-ASCII" on ci.rvm.jp and some RubyCIs'
117-
klassnav = File.read('Klass.html')[%r[<div class="nav-section">.*<div id="class-metadata">]m]
116+
klassnav = File.binread('Klass.html')[%r[<div class="nav-section">.*<div id="class-metadata">]m]
118117
assert_match(
119118
%r[<li>\s*<details open>\s*<summary>\s*<a href=\S+>Heading 1</a>\s*</summary>\s*<ul]m,
120119
klassnav
@@ -131,15 +130,15 @@ def test_generate_page
131130
@g.generate
132131
assert_file 'outer_rdoc.html'
133132
assert_file 'outer/inner_rdoc.html'
134-
index = File.read('index.html')
133+
index = File.binread('index.html')
135134
re = %r[<summary><a href="\./outer_rdoc\.html">outer</a></summary>.*?</details>]m
136135
assert_match(re, index)
137136
summary = index[re]
138137
assert_match %r[<a href="\./outer/inner_rdoc.html">inner</a>], summary
139138
re = %r[<details open><summary><a href="\./outer_rdoc\.html">outer</a></summary>.*?</details>]m
140-
assert_match(re, File.read('outer_rdoc.html'))
139+
assert_match(re, File.binread('outer_rdoc.html'))
141140
re = %r[<details open><summary><a href="\.\./outer_rdoc\.html">outer</a></summary>.*?</details>]m
142-
assert_match(re, File.read('outer/inner_rdoc.html'))
141+
assert_match(re, File.binread('outer/inner_rdoc.html'))
143142
end
144143

145144
def test_generate_dry_run
@@ -276,7 +275,7 @@ def test_generated_filename_with_html_tag
276275
@g.generate
277276

278277
Dir.glob("*.html", base: @tmpdir) do |html|
279-
File.read(File.join(@tmpdir, html)).scan(/.*should be escaped.*/) do |line|
278+
File.binread(File.join(@tmpdir, html)).scan(/.*should be escaped.*/) do |line|
280279
assert_not_include line, "<em>", html
281280
end
282281
end
@@ -294,23 +293,23 @@ def test_template_stylesheets
294293
@g.generate
295294

296295
assert_file base
297-
assert_include File.read('index.html'), %Q[href="./#{base}"]
296+
assert_include File.binread('index.html'), %Q[href="./#{base}"]
298297
end
299298

300299
def test_title
301300
title = "RDoc Test".freeze
302301
@options.title = title
303302
@g.generate
304303

305-
assert_main_title(File.read('index.html'), title)
304+
assert_main_title(File.binread('index.html'), title)
306305
end
307306

308307
def test_title_escape
309308
title = %[<script>alert("RDoc")</script>].freeze
310309
@options.title = title
311310
@g.generate
312311

313-
assert_main_title(File.read('index.html'), title)
312+
assert_main_title(File.binread('index.html'), title)
314313
end
315314

316315
##

0 commit comments

Comments
 (0)