Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Parsing executables with #! and encoding: comment

RDoc::Encoding#set_encoding was stripping the shebang preventing
RDoc::Parser::for from recognizing the file as a ruby executable.  The
file would then be parsed with the Simple (RDoc) parser losing all
internal documentation.

Fixes bug #161
  • Loading branch information...
commit bc67b60d6291b3d3f566ca18b014697d1a41a03a 1 parent 89773ef
@drbrain drbrain authored
View
2  History.rdoc
@@ -15,6 +15,8 @@ to build HTML documentation when installing gems.)
* Fixed HEREDOC output for the limited case of a heredoc followed by a line
end. When a HEREDOC is not followed by a line end RDoc is not currently
smart enough to restore the source correctly. Bug #162 by Zachary Scott.
+ * Fixed parsing of executables with shebang and encoding comments. Bug #161
+ by Marcus Stollsteimer
=== 4.0.0.preview2.1 / 2012-12-14
View
4 lib/rdoc/encoding.rb
@@ -75,7 +75,9 @@ def self.read_file filename, encoding, force_transcode = false
# Sets the encoding of +string+ based on the magic comment
def self.set_encoding string
- first_line = string[/\A(?:#!.*\n)?.*\n/]
+ string =~ /\A(?:#!.*\n)?(.*\n)/
+
+ first_line = $1
name = case first_line
when /^<\?xml[^?]*encoding=(["'])(.*?)\1/ then $2
View
2  test/test_rdoc_encoding.rb
@@ -164,7 +164,7 @@ def test_class_set_encoding_strip
RDoc::Encoding.set_encoding s
- assert_equal "# more comments", s
+ assert_equal "#!/bin/ruby\n# more comments", s
end
def test_class_set_encoding_bad
Please sign in to comment.
Something went wrong with that request. Please try again.