Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/rdoc/encoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

module RDoc::Encoding

HEADER_REGEXP = /^
HEADER_REGEXP = /\A
(?:
\A\#!.*\n
\#!.*\n
|
^\#\s+frozen[-_]string[-_]literal[=:].+\n
|
^\#[^\n]+\b(?:en)?coding[=:]\s*(?<name>[^\s;]+).*\n
^\#\s*(?:-\*-\s*(?:[^;\n]*;\s*)*)?(?:en)?coding[=:]\s*(?<name>[^:\s;]+).*\n
|
<\?xml[^?]*encoding=(?<quote>["'])(?<name>.*?)\k<quote>.*\n
Comment thread
st0012 marked this conversation as resolved.
)+
Expand Down
9 changes: 9 additions & 0 deletions test/rdoc/rdoc_encoding_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ def test_class_detect_encoding
assert_equal Encoding::UTF_8, encoding
end

def test_class_detect_encoding_ignores_documentation_comments
document = "# This document describes a method named #encoding: Returns an object.\n" \
"# Encoding::US_ASCII.name # => \"US-ASCII\"\n" \
"# This is a documentation paragraph.\n" \
"# coding: UTF-8 is example text, not a magic comment.\n"

assert_nil RDoc::Encoding.detect_encoding document
end

def test_class_set_encoding_bad
s = ""
encoding = RDoc::Encoding.detect_encoding s
Expand Down