[dw-free] AJAX expand/collapse of cut entries
[commit: http://hg.dwscoalition.org/dw-free/rev/27c568220cd6]
http://bugs.dwscoalition.org/show_bug.cgi?id=2352
Fixes for when the cuts contain HTML. Additional tests by
fu
Patch by
allen.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=2352
Fixes for when the cuts contain HTML. Additional tests by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- cgi-bin/LJ/CleanHTML.pm
- t/clean-event.t
- t/cleaner-ljtags.t
-------------------------------------------------------------------------------- diff -r 6ab8721bd766 -r 27c568220cd6 cgi-bin/LJ/CleanHTML.pm --- a/cgi-bin/LJ/CleanHTML.pm Fri Jun 04 11:26:45 2010 +0800 +++ b/cgi-bin/LJ/CleanHTML.pm Fri Jun 04 12:06:59 2010 +0800 @@ -310,7 +310,7 @@ sub clean # if we're looking for cut tags, ignore everything that's # not a cut tag. - if ( $eatall && ! $tag eq "lj-cut" ) { + if ( $eatall && $tag ne "lj-cut" ) { next TOKEN; } @@ -897,7 +897,7 @@ sub clean if ( $cuttag_stack[-1] eq $tag ) { pop @cuttag_stack; - $eatall = 1 unless ( @cuttag_stack ); + last TOKEN unless ( @cuttag_stack ); } } diff -r 6ab8721bd766 -r 27c568220cd6 t/clean-event.t --- a/t/clean-event.t Fri Jun 04 11:26:45 2010 +0800 +++ b/t/clean-event.t Fri Jun 04 12:06:59 2010 +0800 @@ -64,4 +64,58 @@ ok($orig_post =~ /^$clean_post$/, "CSS c $clean->({ remove_fonts => 1, remove_sizes => 1 }); ok($orig_post =~ /^$clean_post$/, "CSS fonts and sizes removed"); +# get cut text +my $cut_text; +my $entry_text = qq{<cut text="first">111</cut><cut text="second">2222</cut>}; + +$orig_post = $entry_text; +$cut_text = "111"; +$clean->( { cut_retrieve => 1 } ); +is( $orig_post, $cut_text, "Text under first cut, plain" ); + +$orig_post = $entry_text; +$cut_text = "2222"; +$clean->( { cut_retrieve => 2 } ); +is( $orig_post, $cut_text, "Text under second cut, plain" ); + +$entry_text = qq{ +<cut text="first"><a href="#first">111</a></cut> +<cut text="second"><a href="#second">2222</a></cut>}; + +$orig_post = $entry_text; +$cut_text = qq{<a href="#first">111</a>}; +$clean->( { cut_retrieve => 1 } ); +is( $orig_post, $cut_text, "Text under first cut, with HTML tags" ); + +$orig_post = $entry_text; +$cut_text = qq{<a href="#second">2222</a>}; +$clean->( { cut_retrieve => 2 } ); +is( $orig_post, $cut_text, "Text under second cut, with HTML tags" ); + + +# nested cut tags +$entry_text = qq{<cut text="outer">out <cut text="inner">in</cut></cut>}; + +$orig_post = $entry_text; +$cut_text = qq{out <a name="cutid2"></a>in}; +$clean->( { cut_retrieve => 1 } ); +is( $orig_post, $cut_text, "Text under outer cut, plain" ); + +$orig_post = $entry_text; +$cut_text = qq{in}; +$clean->( { cut_retrieve => 2 } ); +is( $orig_post, $cut_text, "Text under inner cut, plain" ); + +$entry_text = qq{<cut text="outer"><strong>out</strong> <cut text="inner"><em>in</em></cut></cut>}; + +$orig_post = $entry_text; +$cut_text = qq{<strong>out</strong> <a name="cutid2"></a><em>in</em>}; +$clean->( { cut_retrieve => 1 } ); +is( $orig_post, $cut_text, "Text under outer cut, HTML" ); + +$orig_post = $entry_text; +$cut_text = qq{<em>in</em>}; +$clean->( { cut_retrieve => 2 } ); +is( $orig_post, $cut_text, "Text under inner cut, HTML" ); + 1; diff -r 6ab8721bd766 -r 27c568220cd6 t/cleaner-ljtags.t --- a/t/cleaner-ljtags.t Fri Jun 04 11:26:45 2010 +0800 +++ b/t/cleaner-ljtags.t Fri Jun 04 12:06:59 2010 +0800 @@ -33,26 +33,26 @@ is($clean->("[<span class=ljuser>bob <im is($clean->("[<span class=ljuser>bob <img src=\"http://www.lj.bradfitz.com/img/userinfo.gif\" /> system</span>]"), "[$lju_sys]", "span ljuser with junk inside"); -# old lj-ut +# old lj-cut is($clean->("And a cut:<lj-cut>foooooooooooooo</lj-cut>"), - "And a cut:<b>( <a href=\"$fullurl#cutid1\">Read more...</a> )</b>", + "And a cut:<span style=\"display: none;\" id=\"span-cuttag___1\" class=\"cuttag\"></span><b>( <a href=\"$fullurl#cutid1\">Read more...</a> )</b><div style=\"display: none;\" id=\"div-cuttag___1\" aria-live=\"assertive\"></div>", "old lj-cut"); is($clean->("And a cut:<lj-cut text='foo'>foooooooooooooo</lj-cut>"), - "And a cut:<b>( <a href=\"$fullurl#cutid1\">foo</a> )</b>", + "And a cut:<span style=\"display: none;\" id=\"span-cuttag___1\" class=\"cuttag\"></span><b>( <a href=\"$fullurl#cutid1\">foo</a> )</b><div style=\"display: none;\" id=\"div-cuttag___1\" aria-live=\"assertive\"></div>", "old lj-cut w/ text"); # new lj-cut is($clean->(qq{New cut: <div class="ljcut">baaaaaaaaaarrrrr</div>}), - qq{New cut: <div><b>( <a href="http://lj.example/full.html#cutid1">Read more...</a> )</b></div>}, + qq{New cut: <div><span style="display: none;" id="span-cuttag___1" class="cuttag"></span><b>( <a href="http://lj.example/full.html#cutid1">Read more...</a> )</b><div style="display: none;" id="div-cuttag___1" aria-live="assertive"></div></div>}, "new lj-cut w/ div"); is($clean->(qq{New cut: <div class="ljcut" text="This is my div cut">baaaaaaaaaarrrrr</div>}), - qq{New cut: <div><b>( <a href="http://lj.example/full.html#cutid1">This is my div cut</a> )</b></div>}, + qq{New cut: <div><span style="display: none;" id="span-cuttag___1" class="cuttag"></span><b>( <a href="http://lj.example/full.html#cutid1">This is my div cut</a> )</b><div style="display: none;" id="div-cuttag___1" aria-live="assertive"></div></div>}, "new lj-cut w/ div w/ text"); # nested div cuts is($clean->(qq{Nested: <div class="ljcut" text="Nested">baaaaaaaaaa<div style="background: red">I AM RED</div>arrrrrr</div>}), - qq{Nested: <div><b>( <a href="http://lj.example/full.html#cutid1">Nested</a> )</b></div>}, + qq{Nested: <div><span style="display: none;" id="span-cuttag___1" class="cuttag"></span><b>( <a href="http://lj.example/full.html#cutid1">Nested</a> )</b><div style="display: none;" id="div-cuttag___1" aria-live="assertive"></div></div>}, "nested div cuts"); is($clean->(qq{Nested: <div class="ljcut" text="Nested">baaaaaaaaaa<div style="background: red">I AM RED</div>arrrrrr</div>}, cuturl => ""), --------------------------------------------------------------------------------