diff --git a/History.txt b/History.txt index 814b27380b..141dd93699 100644 --- a/History.txt +++ b/History.txt @@ -11,7 +11,7 @@ * Locations of module aliases are now recorded. * RDoc::Parser::C finds method bodies better now. * Fixed further locations where output encoding was not preserved. Bug #11 - by Vít Ondruch. + by Vít Ondruch, RubyForge bug #28791 by Dzmitry Prakapenka. * Fixed display of numeric lists on the index page and file pages. Bug #12 by tobijk. diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb index 61fc0f89f2..bdf02fd236 100644 --- a/lib/rdoc/parser/ruby.rb +++ b/lib/rdoc/parser/ruby.rb @@ -1641,8 +1641,11 @@ def read_documentation_modifiers(context, allow) # Removes private comments from +comment+ def remove_private_comments(comment) - comment.gsub!(/^#--\n.*?^#\+\+\n?/m, '') - comment.sub!(/^#--\n.*\n?/m, '') + empty = '' + empty.force_encoding comment.encoding if Object.const_defined? :Encoding + + comment.gsub!(/^#--\n.*?^#\+\+\n?/m, empty) + comment.sub!(/^#--\n.*\n?/m, empty) end ## diff --git a/test/test_rdoc_parser_ruby.rb b/test/test_rdoc_parser_ruby.rb index 7f23f3afa4..c13d672ee6 100644 --- a/test/test_rdoc_parser_ruby.rb +++ b/test/test_rdoc_parser_ruby.rb @@ -186,6 +186,23 @@ def test_remove_private_comments assert_equal expected, comment end + def test_remove_private_comments_encoding + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + util_parser '' + + comment = <<-EOS +# This is text +#-- +# this is private + EOS + comment.force_encoding Encoding::IBM437 + + @parser.remove_private_comments comment + + assert_equal Encoding::IBM437, comment.encoding + end + def test_remove_private_comments_rule util_parser '' @@ -223,6 +240,45 @@ def test_remove_private_comments_toggle assert_equal expected, comment end + def test_remove_private_comments_toggle_encoding + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + util_parser '' + + comment = <<-EOS +# This is text +#-- +# this is private +#++ +# This is text again. + EOS + + comment.force_encoding Encoding::IBM437 + + @parser.remove_private_comments comment + + assert_equal Encoding::IBM437, comment.encoding + end + + def test_remove_private_comments_toggle_encoding_ruby_bug? + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + util_parser '' + + comment = <<-EOS +#-- +# this is private +#++ +# This is text again. + EOS + + comment.force_encoding Encoding::IBM437 + + @parser.remove_private_comments comment + + assert_equal Encoding::IBM437, comment.encoding + end + def test_look_for_directives_in_commented util_parser ""