Skip to content

Commit b59ca37

Browse files
authored
Merge pull request #430 from dogatana/fix_Encdoing_error_on_Windows
fix an issue that rdoc fails when running on Windows with RUBYOPT=-U
2 parents 663c117 + b1490dd commit b59ca37

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/rdoc/generator/json_index.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def generate_gzipped
170170
outfile = out_dir + "#{search_index_file}.gz"
171171

172172
debug_msg "Reading the JSON index file from %s" % search_index_file
173-
search_index = search_index_file.read
173+
search_index = search_index_file.read(mode: 'r:utf-8')
174174

175175
debug_msg "Writing gzipped search index to %s" % outfile
176176

lib/rdoc/parser.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def self.binary?(file)
7878

7979
return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index("\x00")
8080

81-
mode = "r"
81+
mode = 'r:utf-8' # default source encoding has been chagened to utf-8
8282
s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024.
8383
encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1]
8484
mode = "rb:#{encoding}" if encoding
@@ -180,7 +180,9 @@ def self.check_modeline file_name
180180
return nil if /coding:/i =~ type
181181

182182
type.downcase
183-
rescue ArgumentError # invalid byte sequence, etc.
183+
rescue ArgumentError
184+
rescue Encoding::InvalidByteSequenceError # invalid byte sequence
185+
184186
end
185187

186188
##

0 commit comments

Comments
 (0)