[dw-free] lj-cut autoexpand doesn't work for <div class='ljcut'> style cuts
[commit: http://hg.dwscoalition.org/dw-free/rev/5ae5343a3530]
http://bugs.dwscoalition.org/show_bug.cgi?id=4435
Make the cut expander understand code of the style <div class="lj-
cut"> (probably inserted by the RTE). Includes tests.
Patch by Christopher Schmidt.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=4435
Make the cut expander understand code of the style <div class="lj-
cut"> (probably inserted by the RTE). Includes tests.
Patch by Christopher Schmidt.
Files modified:
- cgi-bin/LJ/CleanHTML.pm
- t/clean-event.t
--------------------------------------------------------------------------------
diff -r 559c2a7636fe -r 5ae5343a3530 cgi-bin/LJ/CleanHTML.pm
--- a/cgi-bin/LJ/CleanHTML.pm Sun May 13 22:47:28 2012 +0800
+++ b/cgi-bin/LJ/CleanHTML.pm Sun May 13 22:52:07 2012 +0800
@@ -301,13 +301,14 @@
{
my $tag = $update_tag->( $token->[1] );
my $attr = $token->[2]; # hashref
+ my $ljcut_div = $tag eq "div" && lc $attr->{class} eq "ljcut";
$good_until = length $newdata;
if (@eatuntil) {
push @capture, $token if $capturing_during_eat;
# have to keep the cut counts consistent even if they're nested
- if ( $tag eq "lj-cut" ) {
+ if ( $tag eq "lj-cut" || $ljcut_div) {
$cutcount++;
}
if ($tag eq $eatuntil[-1]) {
@@ -318,7 +319,7 @@
# if we're looking for cut tags, ignore everything that's
# not a cut tag.
- if ( $eatall && $tag ne "lj-cut" ) {
+ if ( $eatall && $tag ne "lj-cut" && !$ljcut_div ) {
next TOKEN;
}
@@ -479,7 +480,6 @@
}
# stupid hack to remove the class='ljcut' from divs when we're
# disabling them, so we account for the open div normally later.
- my $ljcut_div = $tag eq "div" && lc $attr->{class} eq "ljcut";
if ($ljcut_div && $ljcut_disable) {
$ljcut_div = 0;
}
@@ -1014,6 +1014,12 @@
$opencount{$tag}--;
$tablescope[-1]->{$tag}-- if $opts->{'tablecheck'} && @tablescope;
}
+ # Since this is an end-tag, we can't know if it's the closing
+ # div for a faked <div class="ljcut"> tag, which means that
+ # community moderators can't see <b></cut></b> at the end of one
+ # of those tags; if this was a problem, then the 'S' branch of
+ # this function would need to record the ljcut_div flag in a
+ # state variable which is stashed across tokens.
elsif ($tag eq "lj-cut") {
if ($opts->{'cutpreview'}) {
$newdata .= "<b></cut></b>";
diff -r 559c2a7636fe -r 5ae5343a3530 t/clean-event.t
--- a/t/clean-event.t Sun May 13 22:47:28 2012 +0800
+++ b/t/clean-event.t Sun May 13 22:52:07 2012 +0800
@@ -171,6 +171,23 @@
$clean->( { cut_retrieve => 2 } );
is( $orig_post, $cut_text, "Text under inner cut, HTML" );
+$entry_text = qq{<div class='ljcut'>Text here</div>};
+$orig_post = $entry_text;
+$cut_text = qq{Text here};
+$clean->( { cut_retrieve => 1 } );
+is( $orig_post, $cut_text, "text in <div> style cut is retrieved" );
+
+$entry_text = qq{<div class='ljcut'>Text here</div> <lj-cut>Other text here</lj-cut>};
+$orig_post = $entry_text;
+$cut_text = qq{Text here};
+$clean->( { cut_retrieve => 1 } );
+is( $orig_post, $cut_text, "text in <div> style cut is retrieved" );
+
+$orig_post = $entry_text;
+$cut_text = qq{Other text here};
+$clean->( { cut_retrieve => 2 } );
+is( $orig_post, $cut_text, "text in <lj-cut> style cut after <div> style cut is retrieved" );
+
# embed tags
note("<object> and <embed> tags");
--------------------------------------------------------------------------------
