@@ -1,35 +1,35 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require 'uri' |
|
19 | 19 | |
|
20 | 20 | module Redmine |
|
21 | 21 | module Helpers |
|
22 | 22 | module URL |
|
23 | 23 | def uri_with_safe_scheme?(uri, schemes = ['http', 'https', 'ftp', 'mailto', nil]) |
|
24 | 24 | # URLs relative to the current document or document root (without a protocol |
|
25 | 25 | # separator, should be harmless |
|
26 | return true unless uri.include? ":" | |
|
26 | return true unless uri.to_s.include? ":" | |
|
27 | 27 | |
|
28 | 28 | # Other URLs need to be parsed |
|
29 | 29 | schemes.include? URI.parse(uri).scheme |
|
30 | 30 | rescue URI::InvalidURIError |
|
31 | 31 | false |
|
32 | 32 | end |
|
33 | 33 | end |
|
34 | 34 | end |
|
35 | 35 | end |
@@ -1,80 +1,84 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../../../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class Redmine::WikiFormatting::MarkdownFormatterTest < ActionView::TestCase |
|
21 | 21 | if Object.const_defined?(:Redcarpet) |
|
22 | 22 | |
|
23 | 23 | def setup |
|
24 | 24 | @formatter = Redmine::WikiFormatting::Markdown::Formatter |
|
25 | 25 | end |
|
26 | 26 | |
|
27 | 27 | def test_syntax_error_in_image_reference_should_not_raise_exception |
|
28 | 28 | assert @formatter.new("!>[](foo.png)").to_html |
|
29 | 29 | end |
|
30 | 30 | |
|
31 | def test_empty_image_should_not_raise_exception | |
|
32 | assert @formatter.new("![]()").to_html | |
|
33 | end | |
|
34 | ||
|
31 | 35 | # re-using the formatter after getting above error crashes the |
|
32 | 36 | # ruby interpreter. This seems to be related to |
|
33 | 37 | # https://github.com/vmg/redcarpet/issues/318 |
|
34 | 38 | def test_should_not_crash_redcarpet_after_syntax_error |
|
35 | 39 | @formatter.new("!>[](foo.png)").to_html rescue nil |
|
36 | 40 | assert @formatter.new("").to_html.present? |
|
37 | 41 | end |
|
38 | 42 | |
|
39 | 43 | def test_inline_style |
|
40 | 44 | assert_equal "<p><strong>foo</strong></p>", @formatter.new("**foo**").to_html.strip |
|
41 | 45 | end |
|
42 | 46 | |
|
43 | 47 | def test_not_set_intra_emphasis |
|
44 | 48 | assert_equal "<p>foo_bar_baz</p>", @formatter.new("foo_bar_baz").to_html.strip |
|
45 | 49 | end |
|
46 | 50 | |
|
47 | 51 | def test_wiki_links_should_be_preserved |
|
48 | 52 | text = 'This is a wiki link: [[Foo]]' |
|
49 | 53 | assert_include '[[Foo]]', @formatter.new(text).to_html |
|
50 | 54 | end |
|
51 | 55 | |
|
52 | 56 | def test_redmine_links_with_double_quotes_should_be_preserved |
|
53 | 57 | text = 'This is a redmine link: version:"1.0"' |
|
54 | 58 | assert_include 'version:"1.0"', @formatter.new(text).to_html |
|
55 | 59 | end |
|
56 | 60 | |
|
57 | 61 | def test_should_support_syntax_highligth |
|
58 | 62 | text = <<-STR |
|
59 | 63 | ~~~ruby |
|
60 | 64 | def foo |
|
61 | 65 | end |
|
62 | 66 | ~~~ |
|
63 | 67 | STR |
|
64 | 68 | assert_select_in @formatter.new(text).to_html, 'pre code.ruby.syntaxhl' do |
|
65 | 69 | assert_select 'span.keyword', :text => 'def' |
|
66 | 70 | end |
|
67 | 71 | end |
|
68 | 72 | |
|
69 | 73 | def test_external_links_should_have_external_css_class |
|
70 | 74 | text = 'This is a [link](http://example.net/)' |
|
71 | 75 | assert_equal '<p>This is a <a href="http://example.net/" class="external">link</a></p>', @formatter.new(text).to_html.strip |
|
72 | 76 | end |
|
73 | 77 | |
|
74 | 78 | def test_locals_links_should_not_have_external_css_class |
|
75 | 79 | text = 'This is a [link](/issues)' |
|
76 | 80 | assert_equal '<p>This is a <a href="/issues">link</a></p>', @formatter.new(text).to_html.strip |
|
77 | 81 | end |
|
78 | 82 | |
|
79 | 83 | end |
|
80 | 84 | end |
General Comments 0
You need to be logged in to leave comments.
Login now