##// END OF EJS Templates
Escape HTML comment tags (#1160)....
Jean-Philippe Lang -
r1388:7a969dafacf0
parent child
Show More
@@ -1134,7 +1134,7 class RedCloth < String
1134 ALLOWED_TAGS = %w(redpre pre code)
1134 ALLOWED_TAGS = %w(redpre pre code)
1135
1135
1136 def escape_html_tags(text)
1136 def escape_html_tags(text)
1137 text.gsub!(%r{<(\/?(\w+)[^>\n]*)(>?)}) {|m| ALLOWED_TAGS.include?($2) ? "<#{$1}#{$3}" : "&lt;#{$1}#{'&gt;' if $3}" }
1137 text.gsub!(%r{<(\/?([!\w]+)[^<>\n]*)(>?)}) {|m| ALLOWED_TAGS.include?($2) ? "<#{$1}#{$3}" : "&lt;#{$1}#{'&gt;' unless $3.blank?}" }
1138 end
1138 end
1139 end
1139 end
1140
1140
@@ -141,6 +141,8 class ApplicationHelperTest < HelperTestCase
141 "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>",
141 "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>",
142 "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>",
142 "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>",
143 "<pre><div>content</div></pre>" => "<pre>&lt;div&gt;content&lt;/div&gt;</pre>",
143 "<pre><div>content</div></pre>" => "<pre>&lt;div&gt;content&lt;/div&gt;</pre>",
144 "HTML comment: <!-- no comments -->" => "<p>HTML comment: &lt;!-- no comments --&gt;</p>",
145 "<!-- opening comment" => "<p>&lt;!-- opening comment</p>"
144 }
146 }
145 to_test.each { |text, result| assert_equal result, textilizable(text) }
147 to_test.each { |text, result| assert_equal result, textilizable(text) }
146 end
148 end
General Comments 0
You need to be logged in to leave comments. Login now