fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-01-04 03:48 am

[dw-free] http://bugs.dwscoalition.org/show_bug.cgi?id=1539

[commit: http://hg.dwscoalition.org/dw-free/rev/b9f5b8c8d5c0]

http://bugs.dwscoalition.org/show_bug.cgi?id=1539

Quick fix for breakage on the page caused by open textarea tags.

Patch by [personal profile] exor674.

Files modified:
  • cgi-bin/LJ/CleanHTML.pm
  • t/clean-event.t
--------------------------------------------------------------------------------
diff -r d3f0f161fbb2 -r b9f5b8c8d5c0 cgi-bin/LJ/CleanHTML.pm
--- a/cgi-bin/LJ/CleanHTML.pm	Tue Jan 04 10:40:47 2011 +0800
+++ b/cgi-bin/LJ/CleanHTML.pm	Tue Jan 04 10:44:22 2011 +0800
@@ -1124,6 +1124,12 @@ sub clean
         }
     }
 
+    # if we have a textarea open, we *MUST* close it first
+    if ( $opencount{textarea} ) {
+         $newdata .= "</textarea>";
+    }
+    $opencount{textarea} = 0;
+
     # close any tags that were opened and not closed
     # don't close tags that don't need a closing tag -- otherwise,
     # we output the closing tags in the wrong place (eg, a </td>
diff -r d3f0f161fbb2 -r b9f5b8c8d5c0 t/clean-event.t
--- a/t/clean-event.t	Tue Jan 04 10:40:47 2011 +0800
+++ b/t/clean-event.t	Tue Jan 04 10:44:22 2011 +0800
@@ -136,6 +136,15 @@ is( $orig_post, $cut_text, "Text under f
 $clean->( { cut_retrieve => 2 } );
 is( $orig_post, $cut_text, "Text under second cut, with HTML tags" );
 
+$orig_post  = qq{<strong><textarea></strong>};
+$clean_post = qq{<strong><textarea>&lt;/strong&gt;</textarea></strong>};
+$clean->();
+is( $orig_post, $clean_post, "Open textarea tag" );
+
+$orig_post  = qq{<textarea><textarea></textarea>};
+$clean_post = qq{<textarea>&lt;textarea&gt;</textarea>};
+$clean->();
+is( $orig_post, $clean_post, "Double textarea tag" );
 
 # nested cut tags
 $entry_text = qq{<cut text="outer">out <cut text="inner">in</cut></cut>};
--------------------------------------------------------------------------------