From 463019be0ef7e6988a2606d614faab7b67211652 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Fri, 17 Oct 2014 12:09:30 +0200 Subject: [PATCH] lib/rdoc/markup/to_label.rb (convert): Make labels cross-browser compatible. Percent-encoded URL fragments prevent Firefox from jumping to their respective anchors. Wikipedia (MediaWiki) does something similar, with `.` instead of `-`. There's precedent in `RDoc::{Alias,MethodAttr}#html_name` (54dbcf70) and `RDoc::Context::Section#aref` (431baa1b). This breaks backwards-compatibility, though. --- lib/rdoc/markup/to_label.rb | 2 +- test/test_rdoc_markup_heading.rb | 8 ++++---- test/test_rdoc_markup_to_label.rb | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/rdoc/markup/to_label.rb b/lib/rdoc/markup/to_label.rb index ace89c324a..6fbe4a3dbd 100644 --- a/lib/rdoc/markup/to_label.rb +++ b/lib/rdoc/markup/to_label.rb @@ -31,7 +31,7 @@ def initialize markup = nil def convert text label = convert_flow @am.flow text - CGI.escape label + CGI.escape(label).gsub('%', '-').sub(/^-/, '') end ## diff --git a/test/test_rdoc_markup_heading.rb b/test/test_rdoc_markup_heading.rb index ff53ff5ac3..26d4b5bffc 100644 --- a/test/test_rdoc_markup_heading.rb +++ b/test/test_rdoc_markup_heading.rb @@ -9,16 +9,16 @@ def setup end def test_aref - assert_equal 'label-Hello+Friend%21', @h.aref + assert_equal 'label-Hello+Friend-21', @h.aref end def test_label - assert_equal 'label-Hello+Friend%21', @h.label - assert_equal 'label-Hello+Friend%21', @h.label(nil) + assert_equal 'label-Hello+Friend-21', @h.label + assert_equal 'label-Hello+Friend-21', @h.label(nil) context = RDoc::NormalClass.new 'Foo' - assert_equal 'class-Foo-label-Hello+Friend%21', @h.label(context) + assert_equal 'class-Foo-label-Hello+Friend-21', @h.label(context) end def test_plain_html diff --git a/test/test_rdoc_markup_to_label.rb b/test/test_rdoc_markup_to_label.rb index 5fb358bee3..d8cc365069 100644 --- a/test/test_rdoc_markup_to_label.rb +++ b/test/test_rdoc_markup_to_label.rb @@ -82,8 +82,8 @@ def test_convert_crossref assert_equal 'some_method', @to.convert('some_method') assert_equal 'some_method', @to.convert('\\some_method') - assert_equal '%23some_method', @to.convert('#some_method') - assert_equal '%23some_method', @to.convert('\\#some_method') + assert_equal '23some_method', @to.convert('#some_method') + assert_equal '23some_method', @to.convert('\\#some_method') end def test_convert_em @@ -92,11 +92,11 @@ def test_convert_em end def test_convert_em_dash # for HTML conversion - assert_equal '--', @to.convert('--') + assert_equal '-', @to.convert('--') end def test_convert_escape - assert_equal 'a+%3E+b', @to.convert('a > b') + assert_equal 'a+-3E+b', @to.convert('a > b') end def test_convert_tidylink