@@ -550,6 +550,7 module ApplicationHelper | |||
|
550 | 550 | if page =~ /^(.+?)\#(.+)$/ |
|
551 | 551 | page, anchor = $1, $2 |
|
552 | 552 | end |
|
553 | anchor = sanitize_anchor_name(anchor) if anchor.present? | |
|
553 | 554 | # check if page exists |
|
554 | 555 | wiki_page = link_project.wiki.find_page(page) |
|
555 | 556 | url = if anchor.present? && wiki_page.present? && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page |
@@ -707,7 +708,7 module ApplicationHelper | |||
|
707 | 708 | text.gsub!(HEADING_RE) do |
|
708 | 709 | level, attrs, content = $1.to_i, $2, $3 |
|
709 | 710 | item = strip_tags(content).strip |
|
710 | anchor = item.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-') | |
|
711 | anchor = sanitize_anchor_name(item) | |
|
711 | 712 | @parsed_headings << [level, anchor, item] |
|
712 | 713 | "<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">¶</a></h#{level}>" |
|
713 | 714 | end |
@@ -893,6 +894,10 module ApplicationHelper | |||
|
893 | 894 | end |
|
894 | 895 | end |
|
895 | 896 | |
|
897 | def sanitize_anchor_name(anchor) | |
|
898 | anchor.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-') | |
|
899 | end | |
|
900 | ||
|
896 | 901 | # Returns the javascript tags that are included in the html layout head |
|
897 | 902 | def javascript_heads |
|
898 | 903 | 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">¶</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