From f3b24b5b7f88ecfdefcd898f01ea1cfb2ee418f3 Mon Sep 17 00:00:00 2001 From: drbrain Date: Fri, 4 Jan 2013 06:16:13 +0000 Subject: * lib/rdoc/cross_reference.rb: Fixed matching of C#=== or #===. RDoc bug #164 * test/rdoc/test_rdoc_cross_reference.rb: Test for above. * lib/rdoc/parser/changelog.rb: Fixed parsing of dates. RDoc bug #165 * test/rdoc/test_rdoc_parser_changelog.rb: Test for above. * lib/rdoc/parser.rb: Fixed parsing multibyte files with incomplete characters at byte 1024. [ruby-trunk - Bug #6393] Fixed handling of -E. [ruby-trunk - Bug #6392] * test/rdoc/test_rdoc_options.rb: Test for above. * test/rdoc/test_rdoc_parser.rb: ditto. * test/rdoc/test_rdoc_parser_c.rb: ditto. * test/rdoc/test_rdoc_parser_changelog.rb: ditto. * test/rdoc/test_rdoc_parser_markdown.rb: ditto. * test/rdoc/test_rdoc_parser_rd.rb: ditto. * test/rdoc/test_rdoc_rdoc.rb: ditto. * lib/rdoc/tom_doc.rb: Fixed parsing of [] in TomDoc arguments list. RDoc bug #167 * test/rdoc/test_rdoc_tom_doc.rb: Test for above. * lib/rdoc.rb: Update version. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rdoc/parser.rb | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'lib/rdoc/parser.rb') diff --git a/lib/rdoc/parser.rb b/lib/rdoc/parser.rb index 506b5e7d1b..47ecd746d0 100644 --- a/lib/rdoc/parser.rb +++ b/lib/rdoc/parser.rb @@ -58,7 +58,7 @@ class RDoc::Parser old_ext = old_ext.sub(/^\.(.*)/, '\1') new_ext = new_ext.sub(/^\.(.*)/, '\1') - parser = can_parse "xxx.#{old_ext}" + parser = can_parse_by_name "xxx.#{old_ext}" return false unless parser RDoc::Parser.parsers.unshift [/\.#{new_ext}$/, parser] @@ -77,14 +77,14 @@ class RDoc::Parser 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;]+?)(?:-\*-|[\s;])/, 1] + mode = "r:#{encoding}" if encoding + s = File.open(file, mode) {|f| f.gets(nil, 1024)} not s.valid_encoding? else @@ -131,23 +131,36 @@ class RDoc::Parser zip_signature == "PK\x03\x04" or zip_signature == "PK\x05\x06" or zip_signature == "PK\x07\x08" + rescue + false end ## # Return a parser that can handle a particular extension - def self.can_parse(file_name) - parser = RDoc::Parser.parsers.find { |regexp,| regexp =~ file_name }.last + def self.can_parse file_name + parser = can_parse_by_name file_name # HACK Selenium hides a jar file using a .txt extension return if parser == RDoc::Parser::Simple and zip? file_name + parser + end + + ## + # Returns a parser that can handle the extension for +file_name+. This does + # not depend upon the file being readable. + + def self.can_parse_by_name file_name + _, parser = RDoc::Parser.parsers.find { |regexp,| regexp =~ file_name } + # The default parser must not parse binary files ext_name = File.extname file_name return parser if ext_name.empty? + if parser == RDoc::Parser::Simple and ext_name !~ /txt|rdoc/ then case check_modeline file_name - when 'rdoc' then # continue + when nil, 'rdoc' then # continue else return nil end end @@ -173,6 +186,8 @@ class RDoc::Parser type = $1 end + return nil if /coding:/i =~ type + type.downcase rescue ArgumentError # invalid byte sequence, etc. end @@ -204,6 +219,8 @@ class RDoc::Parser return unless parser parser.new top_level, file_name, content, options, stats + rescue SystemCallError + nil end ## -- cgit v1.2.3