Lines 55-61
Link Here
|
55 |
|
55 |
|
56 |
# elements that change text style |
56 |
# elements that change text style |
57 |
my %elements_text_style = map {; $_ => 1 } |
57 |
my %elements_text_style = map {; $_ => 1 } |
58 |
qw( body font table tr th td big small basefont marquee span p div ), |
58 |
qw( body font table tr th td big small basefont marquee span p div a ), |
59 |
; |
59 |
; |
60 |
|
60 |
|
61 |
# elements that insert whitespace |
61 |
# elements that insert whitespace |
Lines 80-91
Link Here
|
80 |
$ok_attributes{body}{$_} = 1 for qw( text bgcolor link alink vlink background ); |
80 |
$ok_attributes{body}{$_} = 1 for qw( text bgcolor link alink vlink background ); |
81 |
$ok_attributes{font}{$_} = 1 for qw( color face size ); |
81 |
$ok_attributes{font}{$_} = 1 for qw( color face size ); |
82 |
$ok_attributes{marquee}{$_} = 1 for qw( bgcolor background ); |
82 |
$ok_attributes{marquee}{$_} = 1 for qw( bgcolor background ); |
83 |
$ok_attributes{table}{$_} = 1 for qw( bgcolor ); |
83 |
$ok_attributes{table}{$_} = 1 for qw( style bgcolor ); |
84 |
$ok_attributes{td}{$_} = 1 for qw( bgcolor ); |
84 |
$ok_attributes{td}{$_} = 1 for qw( style bgcolor ); |
85 |
$ok_attributes{th}{$_} = 1 for qw( bgcolor ); |
85 |
$ok_attributes{th}{$_} = 1 for qw( style bgcolor ); |
86 |
$ok_attributes{tr}{$_} = 1 for qw( bgcolor ); |
86 |
$ok_attributes{tr}{$_} = 1 for qw( style bgcolor ); |
87 |
$ok_attributes{span}{$_} = 1 for qw( style ); |
87 |
$ok_attributes{span}{$_} = 1 for qw( style ); |
88 |
$ok_attributes{p}{$_} = 1 for qw( style ); |
88 |
$ok_attributes{p}{$_} = 1 for qw( style ); |
|
|
89 |
$ok_attributes{a}{$_} = 1 for qw( style ); |
89 |
$ok_attributes{div}{$_} = 1 for qw( style ); |
90 |
$ok_attributes{div}{$_} = 1 for qw( style ); |
90 |
|
91 |
|
91 |
sub new { |
92 |
sub new { |
Lines 493-512
Link Here
|
493 |
$new{style} = $attr->{style}; |
494 |
$new{style} = $attr->{style}; |
494 |
my @parts = split(/;/, $new{style}); |
495 |
my @parts = split(/;/, $new{style}); |
495 |
foreach (@parts) { |
496 |
foreach (@parts) { |
496 |
if (/^\s*(background-)?color:\s*(.+)\s*$/i) { |
497 |
if (/^\s*(background)?-?color:\s*(.+)\s*$/i) { |
497 |
my $whcolor = $1 ? 'bgcolor' : 'fgcolor'; |
498 |
my $whcolor = $1 ? 'bgcolor' : 'fgcolor'; |
498 |
my $value = lc $2; |
499 |
my $value = lc $2; |
499 |
|
500 |
|
|
|
501 |
# BLD: Protecting from the various word values that background-color may contain |
502 |
next if(($whcolor =~ 'bgcolor') && ($value =~ /(?:inherit|initial|unset|transparent|currentColor)/i)); |
503 |
|
500 |
if ($value =~ /rgb/) { |
504 |
if ($value =~ /rgb/) { |
501 |
$value =~ tr/0-9,//cd; |
505 |
$value =~ tr/0-9,//cd; |
502 |
my @rgb = split(/,/, $value); |
506 |
my @rgb = split(/,/, $value); |
503 |
$new{$whcolor} = sprintf("#%02x%02x%02x", |
507 |
$new{$whcolor} = sprintf("#%02x%02x%02x", |
504 |
map { !$_ ? 0 : $_ > 255 ? 255 : $_ } |
508 |
map { !$_ ? 0 : $_ > 255 ? 255 : $_ } |
505 |
@rgb[0..2]); |
509 |
@rgb[0..2]); |
506 |
} |
510 |
} |
507 |
else { |
511 |
else { |
508 |
$new{$whcolor} = name_to_rgb($value); |
512 |
$new{$whcolor} = name_to_rgb($value); |
509 |
} |
513 |
} |
|
|
514 |
} |
515 |
elsif (/^\s*background:\s*(.*)\s*$/i) { |
516 |
my $bgvalues = $1; |
517 |
# repetitive from above -- need to collapse logic |
518 |
if($bgvalues =~ /.*(rgb\(?[^)]+\)?).*/) { |
519 |
$bgvalues =~ tr/0-9,//cd; |
520 |
my @rgb = split(/,/, $bgvalues); |
521 |
$new{'bgcolor'} = sprintf("#%02x%02x%02x", |
522 |
map { !$_ ? 0 : $_ > 255 ? 255 : $_ } |
523 |
@rgb[0..2]); |
524 |
} else { |
525 |
my @bitbkg = split(' ', $1); |
526 |
foreach (@bitbkg) { |
527 |
next if ($_ =~ /(?:cover|url|repeat|right|top|bottom|center|left|transparent|initial|inherit|fixed|scroll)/); |
528 |
$new{'bgcolor'} = name_to_rgb($_); |
529 |
} |
530 |
} |
510 |
} |
531 |
} |
511 |
elsif (/^\s*([a-z_-]+)\s*:\s*(\S.*?)\s*$/i) { |
532 |
elsif (/^\s*([a-z_-]+)\s*:\s*(\S.*?)\s*$/i) { |
512 |
# "display: none", "visibility: hidden", etc. |
533 |
# "display: none", "visibility: hidden", etc. |
Lines 516-522
Link Here
|
516 |
} |
537 |
} |
517 |
elsif ($name eq "bgcolor") { |
538 |
elsif ($name eq "bgcolor") { |
518 |
# overwrite with hex value, $new{bgcolor} is set below |
539 |
# overwrite with hex value, $new{bgcolor} is set below |
519 |
$attr->{bgcolor} = name_to_rgb($attr->{bgcolor}); |
540 |
$new{'bgcolor'} = name_to_rgb($attr->{bgcolor}); |
520 |
} |
541 |
} |
521 |
else { |
542 |
else { |
522 |
# attribute is probably okay |
543 |
# attribute is probably okay |
Lines 530-535
Link Here
|
530 |
$self->{min_size} = $new{size}; |
551 |
$self->{min_size} = $new{size}; |
531 |
} |
552 |
} |
532 |
} |
553 |
} |
|
|
554 |
|
533 |
push @{ $self->{text_style} }, \%new; |
555 |
push @{ $self->{text_style} }, \%new; |
534 |
} |
556 |
} |
535 |
# explicitly close a tag |
557 |
# explicitly close a tag |
Lines 544-549
Link Here
|
544 |
sub html_font_invisible { |
566 |
sub html_font_invisible { |
545 |
my ($self, $text) = @_; |
567 |
my ($self, $text) = @_; |
546 |
|
568 |
|
|
|
569 |
|
547 |
my $fg = $self->{text_style}[-1]->{fgcolor}; |
570 |
my $fg = $self->{text_style}[-1]->{fgcolor}; |
548 |
my $bg = $self->{text_style}[-1]->{bgcolor}; |
571 |
my $bg = $self->{text_style}[-1]->{bgcolor}; |
549 |
my $size = $self->{text_style}[-1]->{size}; |
572 |
my $size = $self->{text_style}[-1]->{size}; |
Lines 553-558
Link Here
|
553 |
# invisibility |
576 |
# invisibility |
554 |
if (substr($fg,-6) eq substr($bg,-6)) { |
577 |
if (substr($fg,-6) eq substr($bg,-6)) { |
555 |
$self->put_results(font_low_contrast => 1); |
578 |
$self->put_results(font_low_contrast => 1); |
|
|
579 |
#BLD |
580 |
dbg("BLD: Low Contrast hit: fg %s, bg %s (%s)\n", $fg, $bg, $text); |
556 |
return 1; |
581 |
return 1; |
557 |
# near-invisibility |
582 |
# near-invisibility |
558 |
} elsif ($fg =~ /^\#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/) { |
583 |
} elsif ($fg =~ /^\#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/) { |
Lines 575-580
Link Here
|
575 |
# 1.25% of HTML spam right now), but please test any changes first |
600 |
# 1.25% of HTML spam right now), but please test any changes first |
576 |
if ($distance < 12) { |
601 |
if ($distance < 12) { |
577 |
$self->put_results(font_low_contrast => 1); |
602 |
$self->put_results(font_low_contrast => 1); |
|
|
603 |
#BLD |
604 |
dbg("BLD: Low Contrast distance: fg %s, bg %s (%s)\n", $fg, $bg, $text); |
578 |
return 1; |
605 |
return 1; |
579 |
} |
606 |
} |
580 |
} |
607 |
} |
Lines 582-587
Link Here
|
582 |
|
609 |
|
583 |
|
610 |
|
584 |
# invalid color |
611 |
# invalid color |
|
|
612 |
#BLD |
613 |
dbg("BLD: checking color: %s bgcolor %s (%s)\n", $fg, $bg, $text); |
585 |
if ($fg eq 'invalid' or $bg eq 'invalid') { |
614 |
if ($fg eq 'invalid' or $bg eq 'invalid') { |
586 |
$self->put_results(font_invalid_color => 1); |
615 |
$self->put_results(font_invalid_color => 1); |
587 |
return 1; |
616 |
return 1; |
Lines 741-746
Link Here
|
741 |
|
770 |
|
742 |
my $invisible_for_bayes = 0; |
771 |
my $invisible_for_bayes = 0; |
743 |
|
772 |
|
|
|
773 |
|
744 |
# NBSP: UTF-8: C2 A0, ISO-8859-*: A0 |
774 |
# NBSP: UTF-8: C2 A0, ISO-8859-*: A0 |
745 |
if ($text !~ /^(?:[ \t\n\r\f\x0b]|\xc2\xa0)*\z/s) { |
775 |
if ($text !~ /^(?:[ \t\n\r\f\x0b]|\xc2\xa0)*\z/s) { |
746 |
$invisible_for_bayes = $self->html_font_invisible($text); |
776 |
$invisible_for_bayes = $self->html_font_invisible($text); |