--- HTML.pm 2015-04-28 12:56:49.000000000 -0700 +++ HTML.pm 2017-07-18 14:20:39.289302180 -0700 @@ -55,7 +55,7 @@ # elements that change text style my %elements_text_style = map {; $_ => 1 } - qw( body font table tr th td big small basefont marquee span p div ), + qw( body font table tr th td big small basefont marquee span p div a ), ; # elements that insert whitespace @@ -80,12 +80,13 @@ $ok_attributes{body}{$_} = 1 for qw( text bgcolor link alink vlink background ); $ok_attributes{font}{$_} = 1 for qw( color face size ); $ok_attributes{marquee}{$_} = 1 for qw( bgcolor background ); -$ok_attributes{table}{$_} = 1 for qw( bgcolor ); -$ok_attributes{td}{$_} = 1 for qw( bgcolor ); -$ok_attributes{th}{$_} = 1 for qw( bgcolor ); -$ok_attributes{tr}{$_} = 1 for qw( bgcolor ); +$ok_attributes{table}{$_} = 1 for qw( style bgcolor ); +$ok_attributes{td}{$_} = 1 for qw( style bgcolor ); +$ok_attributes{th}{$_} = 1 for qw( style bgcolor ); +$ok_attributes{tr}{$_} = 1 for qw( style bgcolor ); $ok_attributes{span}{$_} = 1 for qw( style ); $ok_attributes{p}{$_} = 1 for qw( style ); +$ok_attributes{a}{$_} = 1 for qw( style ); $ok_attributes{div}{$_} = 1 for qw( style ); sub new { @@ -493,20 +494,40 @@ $new{style} = $attr->{style}; my @parts = split(/;/, $new{style}); foreach (@parts) { - if (/^\s*(background-)?color:\s*(.+)\s*$/i) { + if (/^\s*(background)?-?color:\s*(.+)\s*$/i) { my $whcolor = $1 ? 'bgcolor' : 'fgcolor'; my $value = lc $2; + # BLD: Protecting from the various word values that background-color may contain + next if(($whcolor =~ 'bgcolor') && ($value =~ /(?:inherit|initial|unset|transparent|currentColor)/i)); + if ($value =~ /rgb/) { $value =~ tr/0-9,//cd; my @rgb = split(/,/, $value); - $new{$whcolor} = sprintf("#%02x%02x%02x", - map { !$_ ? 0 : $_ > 255 ? 255 : $_ } + $new{$whcolor} = sprintf("#%02x%02x%02x", + map { !$_ ? 0 : $_ > 255 ? 255 : $_ } @rgb[0..2]); - } + } else { $new{$whcolor} = name_to_rgb($value); } + } + elsif (/^\s*background:\s*(.*)\s*$/i) { + my $bgvalues = $1; + # repetitive from above -- need to collapse logic + if($bgvalues =~ /.*(rgb\(?[^)]+\)?).*/) { + $bgvalues =~ tr/0-9,//cd; + my @rgb = split(/,/, $bgvalues); + $new{'bgcolor'} = sprintf("#%02x%02x%02x", + map { !$_ ? 0 : $_ > 255 ? 255 : $_ } + @rgb[0..2]); + } else { + my @bitbkg = split(' ', $1); + foreach (@bitbkg) { + next if ($_ =~ /(?:cover|url|repeat|right|top|bottom|center|left|transparent|initial|inherit|fixed|scroll)/); + $new{'bgcolor'} = name_to_rgb($_); + } + } } elsif (/^\s*([a-z_-]+)\s*:\s*(\S.*?)\s*$/i) { # "display: none", "visibility: hidden", etc. @@ -516,7 +537,7 @@ } elsif ($name eq "bgcolor") { # overwrite with hex value, $new{bgcolor} is set below - $attr->{bgcolor} = name_to_rgb($attr->{bgcolor}); + $new{'bgcolor'} = name_to_rgb($attr->{bgcolor}); } else { # attribute is probably okay @@ -530,6 +551,7 @@ $self->{min_size} = $new{size}; } } + push @{ $self->{text_style} }, \%new; } # explicitly close a tag @@ -544,6 +566,7 @@ sub html_font_invisible { my ($self, $text) = @_; + my $fg = $self->{text_style}[-1]->{fgcolor}; my $bg = $self->{text_style}[-1]->{bgcolor}; my $size = $self->{text_style}[-1]->{size}; @@ -553,6 +576,8 @@ # invisibility if (substr($fg,-6) eq substr($bg,-6)) { $self->put_results(font_low_contrast => 1); +#BLD +dbg("BLD: Low Contrast hit: fg %s, bg %s (%s)\n", $fg, $bg, $text); return 1; # near-invisibility } elsif ($fg =~ /^\#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/) { @@ -575,6 +600,8 @@ # 1.25% of HTML spam right now), but please test any changes first if ($distance < 12) { $self->put_results(font_low_contrast => 1); +#BLD +dbg("BLD: Low Contrast distance: fg %s, bg %s (%s)\n", $fg, $bg, $text); return 1; } } @@ -582,6 +609,8 @@ # invalid color +#BLD +dbg("BLD: checking color: %s bgcolor %s (%s)\n", $fg, $bg, $text); if ($fg eq 'invalid' or $bg eq 'invalid') { $self->put_results(font_invalid_color => 1); return 1; @@ -741,6 +770,7 @@ my $invisible_for_bayes = 0; + # NBSP: UTF-8: C2 A0, ISO-8859-*: A0 if ($text !~ /^(?:[ \t\n\r\f\x0b]|\xc2\xa0)*\z/s) { $invisible_for_bayes = $self->html_font_invisible($text);