use super::*; #[test] fn wikilinks_does_not_unescape_html_entities_in_link_label() { html_opts!( [extension.wikilinks_title_after_pipe], "This is [[<script>alert(0)</script>|a <link]]", "
This is a <link
\n", no_roundtrip, ); html_opts!( [extension.wikilinks_title_before_pipe], "This is [[a <link|<script>alert(0)</script>]]", "This is a <link
\n", no_roundtrip, ); } #[test] fn wikilinks_sanitizes_the_href_attribute_case_1() { html_opts!( [extension.wikilinks_title_after_pipe], "[[http:'\"injected=attribute><img/src=\"0\"onerror=\"alert(0)\">https://example.com|a]]", "\n", ); html_opts!( [extension.wikilinks_title_before_pipe], "[[a|http:'\"injected=attribute><img/src=\"0\"onerror=\"alert(0)\">https://example.com]]", "\n", ); } #[test] fn wikilinks_sanitizes_the_href_attribute_case_2() { html_opts!( [extension.wikilinks_title_after_pipe], "[['\"><svg><i/class=gl-show-field-errors><input/title=\"<script>alert(0)</script>\"/></svg>https://example.com|a]]", "\n", ); html_opts!( [extension.wikilinks_title_before_pipe], "[[a|'\"><svg><i/class=gl-show-field-errors><input/title=\"<script>alert(0)</script>\"/></svg>https://example.com]]", "\n", ); } #[test] fn wikilinks_title_escape_chars() { html_opts!( [ extension.wikilinks_title_before_pipe, render.escaped_char_spans ], "[[Name \\[of\\] page|http://example.com]]", "\n", no_roundtrip, ); } #[test] fn wikilinks_supersedes_relaxed_autolinks() { html_opts!( [ extension.wikilinks_title_after_pipe, parse.relaxed_autolinks ], "[[http://example.com]]", "\n", ); html_opts!( [ extension.wikilinks_title_before_pipe, parse.relaxed_autolinks ], "[[http://example.com]]", "\n", ); } #[test] fn wikilinks_only_url_in_tables() { html_opts!( [extension.wikilinks_title_after_pipe, extension.table], concat!("| header |\n", "| ------- |\n", "| [[url]] |\n",), concat!( "| header | \n", "
|---|
| url | \n", "
| header | \n", "
|---|
| url | \n", "
| header | \n", "
|---|
| [[url | \n", "
| header | \n", "
|---|
| [[link label | \n", "
{}
\n", long_label); html_opts!( [extension.wikilinks_title_after_pipe], &long_label, &expected, ); } #[test] fn wikilinks_autolinker_ignored() { html_opts!( [extension.wikilinks_title_after_pipe, extension.autolink], "[[http://example.com]]", "\n", ); html_opts!( [extension.wikilinks_title_before_pipe, extension.autolink], "[[http://example.com]]", "\n", ); } #[test] fn sourcepos() { assert_ast_match!( [extension.wikilinks_title_after_pipe], "This [[http://example.com|link label]] that\n", (document (1:1-1:43) [ (paragraph (1:1-1:43) [ (text (1:1-1:5) "This ") (wikilink (1:6-1:38) [ (text (1:27-1:36) "link label") ]) (text (1:39-1:43) " that") ]) ]) ); assert_ast_match!( [extension.wikilinks_title_before_pipe], "This [[link label|http://example.com]] that\n", (document (1:1-1:43) [ (paragraph (1:1-1:43) [ (text (1:1-1:5) "This ") (wikilink (1:6-1:38) [ (text (1:8-1:17) "link label") ]) (text (1:39-1:43) " that") ]) ]) ); assert_ast_match!( [extension.wikilinks_title_before_pipe], "This [[http://example.com]] that\n", (document (1:1-1:32) [ (paragraph (1:1-1:32) [ (text (1:1-1:5) "This ") (wikilink (1:6-1:27) [ (text (1:8-1:25) "http://example.com") ]) (text (1:28-1:32) " that") ]) ]) ); assert_ast_match!( [extension.wikilinks_title_before_pipe], "This [[link\\[label|http://example.com]] that\n", (document (1:1-1:44) [ (paragraph (1:1-1:44) [ (text (1:1-1:5) "This ") (wikilink (1:6-1:39) [ (text (1:8-1:18) "link[label") ]) (text (1:40-1:44) " that") ]) ]) ); }