Skip to content

Commit

Permalink
Work around possible ruby bug in String#gsub!
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Jan 29, 2011
1 parent ff60db2 commit c87fc13
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
7 changes: 5 additions & 2 deletions lib/rdoc/parser/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

##
Expand Down
56 changes: 56 additions & 0 deletions test/test_rdoc_parser_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''

Expand Down Expand Up @@ -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 ""

Expand Down

0 comments on commit c87fc13

Please sign in to comment.