Permalink
Browse files

Pass anchors through #parse_url

This prevents generation of an href like http:#foottext-1
  • Loading branch information...
1 parent 4b60ba6 commit c92b4cc35b5d1637c4204e53f0c43057a938f175 @drbrain drbrain committed Dec 16, 2012
Showing with 14 additions and 4 deletions.
  1. +4 −2 lib/rdoc/markup/formatter.rb
  2. +10 −2 test/test_rdoc_markup_formatter.rb
View
6 lib/rdoc/markup/formatter.rb
@@ -227,13 +227,15 @@ def off_tags res, item
# Extracts and a scheme, url and an anchor id from +url+ and returns them.
def parse_url url
- if url =~ /^rdoc-label:([^:]*)(?::(.*))?/ then
+ case url
+ when /^rdoc-label:([^:]*)(?::(.*))?/ then
scheme = 'link'
path = "##{$1}"
id = " id=\"#{$2}\"" if $2
- elsif url =~ /([A-Za-z]+):(.*)/ then
+ when /([A-Za-z]+):(.*)/ then
scheme = $1.downcase
path = $2
+ when /^#/ then
else
scheme = 'http'
path = url
View
12 test/test_rdoc_markup_formatter.rb
@@ -87,15 +87,23 @@ def test_parse_url
assert_equal nil, id
end
- def test_parse_link
+ def test_parse_url_anchor
+ scheme, url, id = @to.parse_url '#foottext-1'
+
+ assert_equal nil, scheme
+ assert_equal '#foottext-1', url
+ assert_equal nil, id
+ end
+
+ def test_parse_url_link
scheme, url, id = @to.parse_url 'link:README.txt'
assert_equal 'link', scheme
assert_equal 'README.txt', url
assert_equal nil, id
end
- def test_parse_link_id
+ def test_parse_url_link_id
scheme, url, id = @to.parse_url 'link:README.txt#label-foo'
assert_equal 'link', scheme

0 comments on commit c92b4cc

Please sign in to comment.