summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/redcloth.rb2
-rw-r--r--test/unit/helpers/application_helper_test.rb5
2 files changed, 4 insertions, 3 deletions
diff --git a/lib/redcloth.rb b/lib/redcloth.rb
index 5ed23b8f7..7e0c71839 100644
--- a/lib/redcloth.rb
+++ b/lib/redcloth.rb
@@ -1134,7 +1134,7 @@ class RedCloth < String
ALLOWED_TAGS = %w(redpre pre code)
def escape_html_tags(text)
- text.gsub!(%r{<((\/?)(\w+))}) {|m| ALLOWED_TAGS.include?($3) ? "<#{$1}" : "&lt;#{$1}" }
+ text.gsub!(%r{<(\/?(\w+)[^>\n]*)(>?)}) {|m| ALLOWED_TAGS.include?($2) ? "<#{$1}#{$3}" : "&lt;#{$1}#{'&gt;' if $3}" }
end
end
diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb
index 66499c003..f0de341c6 100644
--- a/test/unit/helpers/application_helper_test.rb
+++ b/test/unit/helpers/application_helper_test.rb
@@ -134,8 +134,9 @@ class ApplicationHelperTest < HelperTestCase
def test_html_tags
to_test = {
- "<div>content</div>" => "<p>&lt;div>content&lt;/div></p>",
- "<script>some script;</script>" => "<p>&lt;script>some script;&lt;/script></p>",
+ "<div>content</div>" => "<p>&lt;div&gt;content&lt;/div&gt;</p>",
+ "<div class=\"bold\">content</div>" => "<p>&lt;div class=\"bold\"&gt;content&lt;/div&gt;</p>",
+ "<script>some script;</script>" => "<p>&lt;script&gt;some script;&lt;/script&gt;</p>",
# do not escape pre/code tags
"<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>",
"<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>",