diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-05-03 16:33:22 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-05-03 16:33:22 +0000 |
commit | 9bee6cf51fbbb4c813e92b8dece3e92a84c3d5ed (patch) | |
tree | ca2579ff470cd4dbc84d5040eeb80746e2354b7f | |
parent | 1348e3b9ac686433047b30689159f0e5bc3279dc (diff) | |
download | ruby-9bee6cf51fbbb4c813e92b8dece3e92a84c3d5ed.tar.gz |
rdoc: --extension option fix
* lib/rdoc/parser.rb (RDoc.alias_extension): a real file is irrelevant
to aliasing. [ruby-core:44796][Bug #6392]
* lib/rdoc/parser.rb (RDoc.zip?): non-existent file will not be a zip
file.
* lib/rdoc/parser.rb (RDoc.can_parse_by_name): accept aliased
extension file names.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35532 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | lib/rdoc/parser.rb | 14 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_options.rb | 9 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_parser.rb | 7 |
4 files changed, 37 insertions, 4 deletions
@@ -1,4 +1,13 @@ -Fri May 4 01:31:19 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> +Fri May 4 01:33:20 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * lib/rdoc/parser.rb (RDoc.alias_extension): a real file is irrelevant + to aliasing. [ruby-core:44796][Bug #6392] + + * lib/rdoc/parser.rb (RDoc.zip?): non-existent file will not be a zip + file. + + * lib/rdoc/parser.rb (RDoc.can_parse_by_name): accept aliased + extension file names. * lib/rdoc/parser.rb (RDoc.binary?): binary read data may have incomplete multibyte sequence. [ruby-core:44798][Bug #6393] diff --git a/lib/rdoc/parser.rb b/lib/rdoc/parser.rb index 9cc1485422..2f1b9cde8d 100644 --- a/lib/rdoc/parser.rb +++ b/lib/rdoc/parser.rb @@ -61,7 +61,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] @@ -134,21 +134,29 @@ 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 + 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 + + def self.can_parse_by_name(file_name) + pattern, 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? - return if parser == RDoc::Parser::Simple and ext_name !~ /txt|rdoc/ + return if parser == RDoc::Parser::Simple and ext_name !~ /txt|rdoc/ and file_name[pattern].empty? parser end diff --git a/test/rdoc/test_rdoc_options.rb b/test/rdoc/test_rdoc_options.rb index 763f50b5f0..2f74f45b45 100644 --- a/test/rdoc/test_rdoc_options.rb +++ b/test/rdoc/test_rdoc_options.rb @@ -337,6 +337,15 @@ file 'unreadable' not readable $LOAD_PATH.replace orig_LOAD_PATH end + def test_parse_extension_alias + out, err = capture_io do + @options.parse %w[--extension foobar=rdoc] + end + + assert_empty out + assert_empty err + end + def test_setup_generator test_generator = Class.new do def self.setup_options op diff --git a/test/rdoc/test_rdoc_parser.rb b/test/rdoc/test_rdoc_parser.rb index 37d3b67323..49e845e27b 100644 --- a/test/rdoc/test_rdoc_parser.rb +++ b/test/rdoc/test_rdoc_parser.rb @@ -57,6 +57,13 @@ class TestRDocParser < MiniTest::Unit::TestCase readme_file_name = File.expand_path '../README', __FILE__ assert_equal @RP::Simple, @RP.can_parse(readme_file_name) + + jtest_largerdoc_file_name = File.expand_path '../test.ja.largedoc', __FILE__ + assert_nil @RP.can_parse(jtest_largerdoc_file_name) + + @RP.alias_extension("rdoc", "largedoc") + assert_equal @RP::Simple, @RP.can_parse(jtest_largerdoc_file_name) + end ## |