Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix broken HTML processing, add error checking

  • Loading branch information...
commit 8ecc17762a13decb2fe977eb26aded706949f550 1 parent 3f0d11f
@pudge pudge authored
Showing with 44 additions and 12 deletions.
  1. +27 −11 Slash/DB/MySQL/MySQL.pm
  2. +17 −1 Slash/Utility/Data/Data.pm
View
38 Slash/DB/MySQL/MySQL.pm
@@ -6143,16 +6143,19 @@ sub getCommentTextCached {
my $str = $abbrev_text;
# based on revertQuote() ... we replace the unused
# content with <<LEN>> and then we know how much we
- # removed
+ # removed, and discard $str when done
+ my $bail = 0;
while ($str =~ m|((<p>)?<div class="quote">)(.+)$|sig) {
my($found, $p, $rest) = ($1, $2, $3);
my $pos = pos($str) - (length($found) + length($rest));
pos($str) = $pos + length($found);
my $c = 0;
+ $bail = 1;
while ($str =~ m|(<(/?)div.*?>(</p>)?)|sig) {
my($found, $end, $p2) = ($1, $2, $3);
if ($end && !$c) {
+ $bail = 0; # if we don't get here, something is wrong
my $len = length($found);
my $thislen = pos($str)-$pos;
substr($str, $pos, $thislen) = "<<$thislen>>";
@@ -6164,20 +6167,33 @@ sub getCommentTextCached {
$c++;
}
}
+ if ($bail) {
+ use Data::Dumper;
+ warn "Stuck in endless loop: " . Dumper({
+ found => $found,
+ p => $p,
+ rest => $rest,
+ 'pos' => $pos,
+ str => $str,
+ });
+ last;
+ }
}
- $str =~ s/(?<!<)(<[^<>]+>)/'<<'.length($1).'>>'/ge;
+ unless ($bail) {
+ $str =~ s/(?<!<)(<[^<>]+>)/'<<'.length($1).'>>'/ge;
- my $plen = $this_len = 0;
- while ($str =~ /([^<>]|<<(\d+)>>)/g) {
- my $len1 = length $1;
- if ($2) {
- $this_len += $2;
- } else {
- $this_len += $len1;
- $plen += $len1;
+ my $plen = $this_len = 0;
+ while ($str =~ /([^<>]|<<(\d+)>>)/g) {
+ my $len1 = length $1;
+ if ($2) {
+ $this_len += $2;
+ } else {
+ $this_len += $len1;
+ $plen += $len1;
+ }
+ last if $plen >= $abbreviate_len;
}
- last if $plen >= $abbreviate_len;
}
}
$abbrev_text = chopEntity($abbrev_text, $this_len);
View
18 Slash/Utility/Data/Data.pm
@@ -1503,6 +1503,8 @@ sub processCustomTagsPost {
# revert div class="quote" back to <quote>, handles nesting
sub revertQuote {
my($str) = @_;
+
+ my $bail = 0;
while ($str =~ m|((<p>)?<div class="quote">)(.+)$|sig) {
my($found, $p, $rest) = ($1, $2, $3);
my $pos = pos($str) - (length($found) + length($rest));
@@ -1510,9 +1512,11 @@ sub revertQuote {
pos($str) = $pos + length('<quote>');
my $c = 0;
+ $bail = 1;
while ($str =~ m|(<(/?)div.*?>(</p>)?)|sig) {
my($found, $end, $p2) = ($1, $2, $3);
if ($end && !$c) {
+ $bail = 0; # if we don't get here, something is wrong
my $len = length($found);
# + 4 is for the </p>
my $pl = $p && $p2 ? 4 : 0;
@@ -1525,6 +1529,18 @@ sub revertQuote {
$c++;
}
}
+
+ if ($bail) {
+ use Data::Dumper;
+ warn "Stuck in endless loop: " . Dumper({
+ found => $found,
+ p => $p,
+ rest => $rest,
+ 'pos' => $pos,
+ str => $str,
+ });
+ last;
+ }
}
return($str);
}
@@ -2870,7 +2886,7 @@ print STDERR "_validateLists logic error, no entry for list '$list'\n" if !$insi
my $in = '';
# the secondary loop finds either a tag, or text between tags
- while ($content =~ m!\s*([^<]+|<(.+?)>)!sig) {
+ while ($content =~ m!\s*([^<]+|<([^\s>]+).*?>)!sig) {
my($whole, $tag) = ($1, $2);
next if $whole !~ /\S/;
# we only care here if this is one that can be inside a list
Please sign in to comment.
Something went wrong with that request. Please try again.