diff --git a/lib/rdoc/generator/json_index.rb b/lib/rdoc/generator/json_index.rb index 931438b3c3..ea9384e6d3 100644 --- a/lib/rdoc/generator/json_index.rb +++ b/lib/rdoc/generator/json_index.rb @@ -170,7 +170,7 @@ def generate_gzipped outfile = out_dir + "#{search_index_file}.gz" debug_msg "Reading the JSON index file from %s" % search_index_file - search_index = search_index_file.read + search_index = search_index_file.read(mode: 'r:utf-8') debug_msg "Writing gzipped search index to %s" % outfile diff --git a/lib/rdoc/parser.rb b/lib/rdoc/parser.rb index 5abc374bf7..89ac3f1c2a 100644 --- a/lib/rdoc/parser.rb +++ b/lib/rdoc/parser.rb @@ -78,7 +78,7 @@ def self.binary?(file) return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index("\x00") - mode = "r" + mode = 'r:utf-8' # default source encoding has been chagened to utf-8 s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024. encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1] mode = "rb:#{encoding}" if encoding @@ -180,7 +180,9 @@ def self.check_modeline file_name return nil if /coding:/i =~ type type.downcase - rescue ArgumentError # invalid byte sequence, etc. + rescue ArgumentError + rescue Encoding::InvalidByteSequenceError # invalid byte sequence + end ##