@@ -84,12 +84,17 @@ def test_auto_link_with_block_with_html
8484
8585 def test_auto_link_should_sanitize_input_when_sanitize_option_is_not_false
8686 link_raw = %{http://www.rubyonrails.com?id=1&num=2}
87- assert_equal %{<a href="http://www.rubyonrails.com?id=1&num=2">http://www.rubyonrails.com?id=1&num=2</a>} , auto_link ( link_raw )
87+ malicious_script = '<script>alert("malicious!")</script>'
88+ assert_equal %{<a href="http://www.rubyonrails.com?id=1&num=2">http://www.rubyonrails.com?id=1&num=2</a>} , auto_link ( "#{ link_raw } #{ malicious_script } " )
89+ assert auto_link ( "#{ link_raw } #{ malicious_script } " ) . html_safe?
8890 end
8991
9092 def test_auto_link_should_not_sanitize_input_when_sanitize_option_is_false
9193 link_raw = %{http://www.rubyonrails.com?id=1&num=2}
92- assert_equal %{<a href="http://www.rubyonrails.com?id=1&num=2">http://www.rubyonrails.com?id=1&num=2</a>} , auto_link ( link_raw , :sanitize => false )
94+ malicious_script = '<script>alert("malicious!")</script>'
95+
96+ assert_equal %{<a href="http://www.rubyonrails.com?id=1&num=2">http://www.rubyonrails.com?id=1&num=2</a><script>alert("malicious!")</script>} , auto_link ( "#{ link_raw } #{ malicious_script } " , :sanitize => false )
97+ assert !auto_link ( "#{ link_raw } #{ malicious_script } " , :sanitize => false ) . html_safe?
9398 end
9499
95100 def test_auto_link_other_protocols
@@ -114,7 +119,7 @@ def test_auto_link_already_linked
114119 linked5 = %('<a href="#close">close</a> <a href="http://www.example.com"><b>www.example.com</b></a>')
115120 assert_equal linked1 , auto_link ( linked1 )
116121 assert_equal linked2 , auto_link ( linked2 )
117- assert_equal linked3 , auto_link ( linked3 )
122+ assert_equal linked3 , auto_link ( linked3 , :sanitize => false )
118123 assert_equal linked4 , auto_link ( linked4 )
119124 assert_equal linked5 , auto_link ( linked5 )
120125
@@ -130,14 +135,25 @@ def test_auto_link_at_eol
130135 assert_equal %(<p><a href="#{ url1 } ">#{ url1 } </a><br /><a href="#{ url2 } ">#{ url2 } </a><br /></p>) , auto_link ( "<p>#{ url1 } <br />#{ url2 } <br /></p>" )
131136 end
132137
133- def test_auto_link_should_not_be_html_safe
134- 135- link_raw = 'http://www.rubyonrails.org'
136-
137- assert !auto_link ( nil ) . html_safe? , 'should not be html safe'
138- assert !auto_link ( '' ) . html_safe? , 'should not be html safe'
139- assert !auto_link ( "#{ link_raw } #{ link_raw } #{ link_raw } " ) . html_safe? , 'should not be html safe'
140- assert !auto_link ( "hello #{ email_raw } " ) . html_safe? , 'should not be html safe'
138+ def test_auto_link_should_be_html_safe
139+ 140+ link_raw = 'http://www.rubyonrails.org'
141+ malicious_script = '<script>alert("malicious!")</script>'
142+
143+ assert auto_link ( nil ) . html_safe? , 'should be html safe'
144+ assert auto_link ( '' ) . html_safe? , 'should be html safe'
145+ assert auto_link ( "#{ link_raw } #{ link_raw } #{ link_raw } " ) . html_safe? , 'should be html safe'
146+ assert auto_link ( "hello #{ email_raw } " ) . html_safe? , 'should be html safe'
147+ assert auto_link ( "hello #{ email_raw } #{ malicious_script } " ) . html_safe? , 'should be html safe'
148+ end
149+
150+ def test_auto_link_should_not_be_html_safe_when_sanitize_option_false
151+ 152+ link_raw = 'http://www.rubyonrails.org'
153+
154+ assert !auto_link ( "hello" , :sanitize => false ) . html_safe? , 'should not be html safe'
155+ assert !auto_link ( "#{ link_raw } #{ link_raw } #{ link_raw } " , :sanitize => false ) . html_safe? , 'should not be html safe'
156+ assert !auto_link ( "hello #{ email_raw } " , :sanitize => false ) . html_safe? , 'should not be html safe'
141157 end
142158
143159 def test_auto_link_email_address
0 commit comments