Permalink
Browse files

Fixed mangling of email addresses. Fixes #140

RDoc::Markup::AttributeManager#convert_specials now uses the first
capture, if present for creating a special.  This allows anchoring in
the regular expressions used to recognize specials.

Fixed RDoc::Markup::AttrChanger#inspect, #to_s and
RDoc::Markup::Special#inspect by removing the display of attribute names.
Unfortunately this harms diagnostics, but there's no connection back to
the attribute names.
  • Loading branch information...
drbrain committed Nov 20, 2012
1 parent 93be7de commit 84d57273709e071726b7d472ae9cbee152657ea8
View
@@ -104,6 +104,8 @@
* RDoc::Markup::Parser now correctly matches indentation of lists when
multibyte characters are used in the list labels. Issue #140 by
burningTyger
+ * Fixed mangling of email addresses that look like labels. Issue #129 by
+ Tobias Koch
=== 3.12 / 2011-12-15
View
@@ -27,69 +27,76 @@ class RDoc::CrossReference
# have been suppressed, since the suppression characters are removed by the
# code that is triggered.
- CROSSREF_REGEXP = /(
- # A::B::C.meth
- #{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
-
- # Stand-alone method (preceded by a #)
- | \\?\##{METHOD_REGEXP_STR}
-
- # Stand-alone method (preceded by ::)
- | ::#{METHOD_REGEXP_STR}
-
- # A::B::C
- # The stuff after CLASS_REGEXP_STR is a
- # nasty hack. CLASS_REGEXP_STR unfortunately matches
- # words like dog and cat (these are legal "class"
- # names in Fortran 95). When a word is flagged as a
- # potential cross-reference, limitations in the markup
- # engine suppress other processing, such as typesetting.
- # This is particularly noticeable for contractions.
- # In order that words like "can't" not
- # be flagged as potential cross-references, only
- # flag potential class cross-references if the character
- # after the cross-reference is a space, sentence
- # punctuation, tag start character, or attribute
- # marker.
- | #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)
-
- # Things that look like filenames
- # The key thing is that there must be at least
- # one special character (period, slash, or
- # underscore).
- | (?:\.\.\/)*[-\/\w]+[_\/.][-\w\/.]+
-
- # Things that have markup suppressed
- # Don't process things like '\<' in \<tt>, though.
- # TODO: including < is a hack, not very satisfying.
- | \\[^\s<]
+ CROSSREF_REGEXP = /(?:^|\s)
+ (
+ (?:
+ # A::B::C.meth
+ #{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
+
+ # Stand-alone method (preceded by a #)
+ | \\?\##{METHOD_REGEXP_STR}
+
+ # Stand-alone method (preceded by ::)
+ | ::#{METHOD_REGEXP_STR}
+
+ # A::B::C
+ # The stuff after CLASS_REGEXP_STR is a
+ # nasty hack. CLASS_REGEXP_STR unfortunately matches
+ # words like dog and cat (these are legal "class"
+ # names in Fortran 95). When a word is flagged as a
+ # potential cross-reference, limitations in the markup
+ # engine suppress other processing, such as typesetting.
+ # This is particularly noticeable for contractions.
+ # In order that words like "can't" not
+ # be flagged as potential cross-references, only
+ # flag potential class cross-references if the character
+ # after the cross-reference is a space, sentence
+ # punctuation, tag start character, or attribute
+ # marker.
+ | #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)
+
+ # Things that look like filenames
+ # The key thing is that there must be at least
+ # one special character (period, slash, or
+ # underscore).
+ | (?:\.\.\/)*[-\/\w]+[_\/.][-\w\/.]+
+
+ # Things that have markup suppressed
+ # Don't process things like '\<' in \<tt>, though.
+ # TODO: including < is a hack, not very satisfying.
+ | \\[^\s<]
)
# labels for headings
- (?:@[\w+%-]+)?/x
+ (?:@[\w+%-]+(?:\.[\w|%-]+)?)?
+ )/x
##
# Version of CROSSREF_REGEXP used when <tt>--hyperlink-all</tt> is specified.
- ALL_CROSSREF_REGEXP = /(
- # A::B::C.meth
- #{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
+ ALL_CROSSREF_REGEXP = /
+ (?:^|\s)
+ (
+ (?:
+ # A::B::C.meth
+ #{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
- # Stand-alone method
- | \\?#{METHOD_REGEXP_STR}
+ # Stand-alone method
+ | \\?#{METHOD_REGEXP_STR}
- # A::B::C
- | #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)
+ # A::B::C
+ | #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)
- # Things that look like filenames
- | (?:\.\.\/)*[-\/\w]+[_\/.][-\w\/.]+
+ # Things that look like filenames
+ | (?:\.\.\/)*[-\/\w]+[_\/.][-\w\/.]+
- # Things that have markup suppressed
- | \\[^\s<]
+ # Things that have markup suppressed
+ | \\[^\s<]
)
# labels for headings
- (?:@[\w+%-]+)?/x
+ (?:@[\w+%-]+)?
+ )/x
##
# Hash of references that have been looked-up to their replacements
@@ -11,14 +11,11 @@ class RDoc::Markup
class RDoc::Markup::AttrChanger
def to_s # :nodoc:
- "Attr: +#{RDoc::Markup::Attribute.as_string turn_on}/-#{RDoc::Markup::Attribute.as_string turn_off}"
+ "Attr: +#{turn_on}/-#{turn_off}"
end
def inspect # :nodoc:
- "+%s/-%s" % [
- RDoc::Markup::Attribute.as_string(turn_on),
- RDoc::Markup::Attribute.as_string(turn_off),
- ]
+ '+%d/-%d' % [turn_on, turn_off]
end
end
@@ -167,12 +167,15 @@ def convert_html(str, attrs)
##
# Converts special sequences to RDoc attributes
- def convert_specials(str, attrs)
+ def convert_specials str, attrs
unless @special.empty?
- @special.each do |regexp, attr|
+ @special.each do |regexp, attribute|
str.scan(regexp) do
- attrs.set_attrs($`.length, $&.length,
- attr | @attributes.special)
+ capture = $~.size == 1 ? 0 : 1
+
+ s, e = $~.offset capture
+
+ attrs.set_attrs s, e - s, attribute | @attributes.special
end
end
end
@@ -28,8 +28,8 @@ def ==(o)
end
def inspect # :nodoc:
- "#<RDoc::Markup::Special:0x%x @type=%p, name=%p @text=%p>" % [
- object_id, @type, RDoc::Markup::Attribute.as_string(type), text.dump]
+ "#<RDoc::Markup::Special:0x%x @type=%p, @text=%p>" % [
+ object_id, @type, text.dump]
end
def to_s # :nodoc:
@@ -70,6 +70,8 @@ def cross_reference name, text = nil
def handle_special_CROSSREF(special)
name = special.text
+ return name if name =~ /@[\w_-]+\.[\w_-]/ # labels that look like emails
+
unless @hyperlink_all then
# This ensures that words entirely consisting of lowercase letters will
# not have cross-references generated (to suppress lots of erroneous
@@ -167,6 +167,22 @@ def test_handle_special_TIDYLINK_label
link, 'C1#m@foo'
end
+ def test_to_html_CROSSREF_email
+ @options.hyperlink_all = false
+
+ @to = RDoc::Markup::ToHtmlCrossref.new @options, 'index.html', @c1
+
+ result = @to.to_html 'first.last@example.com'
+
+ assert_equal 'first.last@example.com', result
+ end
+
+ def test_to_html_CROSSREF_email_hyperlink_all
+ result = @to.to_html 'first.last@example.com'
+
+ assert_equal 'first.last@example.com', result
+ end
+
def test_link
assert_equal 'n', @to.link('n', 'n')

0 comments on commit 84d5727

Please sign in to comment.