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