##// END OF EJS Templates
Make sure that anchor names generated for headings fully match wiki links (#7215)....
Etienne Massip -
r7443:65b533a8ec1f
parent child
Show More
@@ -570,6 +570,7 module ApplicationHelper
570 570 if page =~ /^(.+?)\#(.+)$/
571 571 page, anchor = $1, $2
572 572 end
573 anchor = sanitize_anchor_name(anchor) if anchor.present?
573 574 # check if page exists
574 575 wiki_page = link_project.wiki.find_page(page)
575 576 url = if anchor.present? && wiki_page.present? && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page
@@ -727,7 +728,7 module ApplicationHelper
727 728 text.gsub!(HEADING_RE) do
728 729 level, attrs, content = $1.to_i, $2, $3
729 730 item = strip_tags(content).strip
730 anchor = item.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
731 anchor = sanitize_anchor_name(item)
731 732 # used for single-file wiki export
732 733 anchor = "#{obj.page.title}_#{anchor}" if options[:wiki_links] == :anchor && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version))
733 734 @parsed_headings << [level, anchor, item]
@@ -919,6 +920,10 module ApplicationHelper
919 920 end
920 921 end
921 922
923 def sanitize_anchor_name(anchor)
924 anchor.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
925 end
926
922 927 # Returns the javascript tags that are included in the html layout head
923 928 def javascript_heads
924 929 tags = javascript_include_tag(:defaults)
@@ -553,6 +553,16 EXPECTED
553 553 assert_equal expected, textilizable(raw)
554 554 end
555 555
556 def test_headings_with_special_chars
557 # This test makes sure that the generated anchor names match the expected
558 # ones even if the heading text contains unconventional characters
559 raw = 'h1. Some heading related to version 0.5'
560 anchor = sanitize_anchor_name("Some-heading-related-to-version-0.5")
561 expected = %|<a name="#{anchor}"></a>\n<h1 >Some heading related to version 0.5<a href="##{anchor}" class="wiki-anchor">&para;</a></h1>|
562
563 assert_equal expected, textilizable(raw)
564 end
565
556 566 def test_wiki_links_within_wiki_page_context
557 567
558 568 page = WikiPage.find_by_title('Another_page' )
General Comments 0
You need to be logged in to leave comments. Login now