| 1374 |
1374 |
end
|
| 1375 |
1375 |
|
| 1376 |
1376 |
def test_headings_with_special_chars
|
| 1377 |
|
# This test makes sure that the generated anchor names match the expected
|
| 1378 |
|
# ones even if the heading text contains unconventional characters
|
| 1379 |
|
raw = 'h1. Some heading related to version 0.5'
|
| 1380 |
|
anchor = sanitize_anchor_name("Some-heading-related-to-version-0.5")
|
| 1381 |
|
expected =
|
| 1382 |
|
%|<a name="#{anchor}"></a>\n<h1 >Some heading related to version 0.5| +
|
| 1383 |
|
%|<a href="##{anchor}" class="wiki-anchor">¶</a></h1>|
|
| 1384 |
|
with_settings :text_formatting => 'textile' do
|
| 1385 |
|
assert_equal expected, textilizable(raw)
|
|
1377 |
# Each value is [expected anchor name, expected HTML-escaped TOC text].
|
|
1378 |
headings = {
|
|
1379 |
'Some heading related to version 0.5' =>
|
|
1380 |
['Some-heading-related-to-version-05', 'Some heading related to version 0.5'],
|
|
1381 |
"Bob's guide" => ['Bobs-guide', 'Bob's guide'],
|
|
1382 |
'The "quoted" guide' => ['The-quoted-guide', 'The "quoted" guide'],
|
|
1383 |
"*Bob's* & B" => ['Bobs-amp-B', 'Bob's & B'],
|
|
1384 |
'<img src=x onerror=alert(1)>' =>
|
|
1385 |
['ltimg-srcx-onerroralert1gt', '<img src=x onerror=alert(1)>']
|
|
1386 |
}
|
|
1387 |
|
|
1388 |
{'textile' => 'h1.', 'common_mark' => '#'}.each do |format, prefix|
|
|
1389 |
with_settings :text_formatting => format do
|
|
1390 |
headings.each do |heading, (anchor, escaped_heading)|
|
|
1391 |
raw = "{{toc}}\n\n#{prefix} #{heading}\n\n[[##{anchor}|Wiki link]]"
|
|
1392 |
html = textilizable(raw)
|
|
1393 |
|
|
1394 |
assert_select_in html, 'a[name=?]', anchor, :count => 1
|
|
1395 |
assert_select_in html, 'h1 a.wiki-anchor[href=?]', "##{anchor}", :count => 1
|
|
1396 |
assert_include %(<a href="##{anchor}">#{escaped_heading}</a>), html
|
|
1397 |
assert_select_in html, 'a.wiki-page[href=?]', "##{anchor}", :text => 'Wiki link'
|
|
1398 |
end
|
|
1399 |
end
|
| 1386 |
1400 |
end
|
| 1387 |
1401 |
end
|
| 1388 |
1402 |
|