Index: test/unit/helpers/application_helper_test.rb
===================================================================
--- test/unit/helpers/application_helper_test.rb (revision 2845)
+++ test/unit/helpers/application_helper_test.rb (working copy)
@@ -304,7 +304,7 @@
end
def test_table_of_content
- raw = <<-RAW
+ raw = <<-'RAW'
{{toc}}
h1. Title
@@ -321,14 +321,23 @@
h1. Another title
+h2. Subtitle with x%x% redcloth3 dummy character
+
+h2. Subtitle with "#$%'()*+,-./:;<=>?@[\]^_{|}~ incorrect characters
+
+h2. Subtitle with russian character "абв" (utf8)
+
RAW
expected = '
'
assert textilizable(raw).gsub("\n", "").include?(expected)
Index: lib/redmine/wiki_formatting/textile/formatter.rb
===================================================================
--- lib/redmine/wiki_formatting/textile/formatter.rb (revision 2845)
+++ lib/redmine/wiki_formatting/textile/formatter.rb (working copy)
@@ -66,13 +66,21 @@
def textile_p_withtoc(tag, atts, cite, content)
# removes wiki links from the item
toc_item = content.gsub(/(\[\[([^\]\|]*)(\|([^\]]*))?\]\])/) { $4 || $2 }
+
# removes styles
# eg. %{color:red}Triggers% => Triggers
toc_item.gsub! %r[%\{[^\}]*\}([^%]+)%], '\\1'
- # replaces non word caracters by dashes
- anchor = toc_item.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
+ # removes all except the alphabet, digits, hyphens
+ # and dummy character of incoming ampersand (see redcloth3)
+ # for compatibility with rfc952, also replace space and repeatable hyphens
+ anchor = toc_item.gsub(%r{[^\w\s\-]|_|(x\%x\%)}, '').gsub(%r{\s+(\-+\s*)?}, '-')
+ # ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed
+ # by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"),
+ # colons (":"), and periods ("."). (http://www.w3.org/TR/html4/types.html#h-6.2)
+ anchor = 'h-' + CGI.escape(anchor).gsub('%', '.')
+
unless anchor.blank?
if tag =~ /^h(\d)$/
@toc << [$1.to_i, anchor, toc_item]