Project

General

Profile

Bug #6393 ยป 0002-rdoc-non-binary-multibyte.patch

nobu (Nobuyoshi Nakada), 05/02/2012 03:47 PM

View differences:

lib/rdoc/parser.rb
have_encoding = s.respond_to? :encoding
if have_encoding then
return false if s.encoding != Encoding::ASCII_8BIT and s.valid_encoding?
end
return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index("\x00")
if have_encoding then
s.force_encoding Encoding.default_external
mode = "r"
s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024.
encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*\([^\s;]+?\)(?:-\*-)?/, 1]
mode = "r:#{encoding}" if encoding
s = File.open(file, mode) {|f| f.gets(nil, 1024)}
not s.valid_encoding?
else
    (1-1/1)