| 1 | package HTML::Anchor::Audit; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use 5.016; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 12 | ▶ | use Encode qw(encode decode FB_CROAK FB_DEFAULT); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use HTML::Parser 3.72; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 12 | ▶ | use Unicode::Normalize qw(NFC); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 12 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | 12 | our @EXPORT_OK = qw(audit_html audit_utf8); | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 9 | ▶ | sub audit_utf8 { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
audit_utf8: called CC=5 SCAR=16.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 9 | my ($bytes, @options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | 9 | ▶ | croak 'audit_utf8 expects a scalar of UTF-8 bytes' if !defined($bytes) || ref($bytes); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $bytes or ref $bytes
MC/DC0%0/2
not defined $bytes or ref $bytes
not defined $bytes
ref $bytes
Truth table33%1/3
not(A) or B
A= not defined $bytesB= ref $bytes
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 9 | ▶ | croak 'audit_utf8 expects bytes, not a wide-character string' if $bytes =~ /[^\x00-\xFF]/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 9 | my $text = eval { decode('UTF-8', $bytes, FB_CROAK) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 9 | ▶ | croak 'Input is not valid UTF-8' if $@; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | return audit_html($text, @options); | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 53 | ▶ | sub audit_html { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
audit_html: called CC=33 SCAR=35.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 53 | my ($html, @options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | 53 | ▶ | croak 'audit_html expects a decoded character string' if !defined($html) || ref($html); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $html or ref $html
MC/DC100%2/2
not defined $html or ref $html
not defined $html
ref $html
Truth table100%3/3
not(A) or B
A= not defined $htmlB= ref $html
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 51 | ▶ | croak 'Options must be key/value pairs' if @options % 2; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 50 | my %opts = @options; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | 50 | for my $key (keys %opts) { | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | 15 | ▶ | croak "Unknown option: $key" if $key ne 'max_bytes' && $key ne 'max_issues'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key ne "max_bytes" and $key ne "max_issues"
MC/DC100%2/2
$key ne "max_bytes" and $key ne "max_issues"
$key ne "max_bytes"
$key ne "max_issues"
Truth table100%3/3
A and B
A= $key ne "max_bytes"B= $key ne "max_issues"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | croak "$key must be a positive integer" if !defined($opts{$key}) || ref($opts{$key}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 14 | ▶ | || $opts{$key} !~ /\A[1-9][0-9]*\z/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not defined $opts{$key} or ref $opts{$key} or not $opts{$key} =~ /\A[1-9][0-9]*\z/u
not defined $opts{$key} or ref $opts{$key}
MC/DC33%1/3
not defined $opts{$key} or ref $opts{$key} or not $opts{$key} =~ /\A[1-9][0-9]*\z/u
not defined $opts{$key}
ref $opts{$key}
not $opts{$key} =~ /\A[1-9][0-9]*\z/u
Truth table50%2/4
not(A) or B or not(C)
A= not defined $opts{$key}B= ref $opts{$key}C= not $opts{$key} =~ /\A[1-9][0-9]*\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 47 | ▶ | my $max_bytes = $opts{max_bytes} // (2 * 1024 * 1024); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts{"max_bytes"} // 2097152
MC/DC100%1/1
$opts{"max_bytes"} // 2097152
$opts{"max_bytes"}
Truth table100%2/2
A
A= $opts{"max_bytes"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 47 | ▶ | my $max_issues = $opts{max_issues} // 500; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts{"max_issues"} // 500
MC/DC100%1/1
$opts{"max_issues"} // 500
$opts{"max_issues"}
Truth table100%2/2
A
A= $opts{"max_issues"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 47 | ▶ | croak "Input exceeds max_bytes ($max_bytes)" if length($html) > $max_bytes; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 47 | my $bytes = eval { encode('UTF-8', $html, FB_CROAK) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 47 | ▶ | croak 'Input contains an invalid Unicode character' if $@; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 47 | ▶ | croak "Input exceeds max_bytes ($max_bytes)" if length($bytes) > $max_bytes; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 46 | my @line_starts = (0); | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 46 | ▶ | while ($bytes =~ /\r\n|\r|\n/g) { push @line_starts, pos($bytes) } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 46 | my (@targets, @refs, @issues); | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | 46 | my (%ids, %names, %normalized); | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 46 | my ($template_depth, $base_href, $out_of_scope, $total_issues) = (0, undef, 0, 0); | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | 46 | my ($cached_line, $cached_offset, $cached_column) = (-1, 0, 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 10143 | ▶ | my $location = sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 10143 | my ($offset, $tag) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 10143 | my ($lo, $hi) = (0, $#line_starts); | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 10143 | ▶ | while ($lo < $hi) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 33 | my $mid = int(($lo + $hi + 1) / 2); | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | 33 | ▶ | if ($line_starts[$mid] <= $offset) { $lo = $mid } else { $hi = $mid - 1 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 10143 | ▶ | my $start = $cached_line == $lo && $offset >= $cached_offset | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cached_line == $lo and $offset >= $cached_offset
MC/DC50%1/2
$cached_line == $lo and $offset >= $cached_offset
$cached_line == $lo
$offset >= $cached_offset
Truth table66%2/3
A and B
A= $cached_line == $loB= $offset >= $cached_offset
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | ? $cached_offset : $line_starts[$lo]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 10143 | ▶ | my $base_column = $start == $cached_offset && $cached_line == $lo ? $cached_column : 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$start == $cached_offset and $cached_line == $lo
MC/DC100%2/2
$start == $cached_offset and $cached_line == $lo
$start == $cached_offset
$cached_line == $lo
Truth table100%3/3
A and B
A= $start == $cached_offsetB= $cached_line == $lo
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 10143 | my $prefix = substr($bytes, $start, $offset - $start); | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | 10143 | my $column = $base_column + length(decode('UTF-8', $prefix, FB_CROAK)); | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | 10143 | ($cached_line, $cached_offset, $cached_column) = ($lo, $offset, $column); | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | 10143 | return { tag => $tag, line => $lo + 1, | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | column => $column, | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | byte_column => $offset - $line_starts[$lo] + 1, byte_offset => $offset }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 46 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 71 | ▶ | my $add_issue = sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 71 | my ($issue) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 71 | $total_issues++; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 71 | ▶ | push @issues, $issue if @issues < $max_issues; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 46 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | 46 | my $parser = HTML::Parser->new(api_version => 3); | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | 46 | $parser->utf8_mode(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 10148 | ▶ | $parser->handler(start => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=23 SCAR=31.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 10148 | my ($tag, $attr, $offset) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 10148 | ▶ | if ($tag eq 'template') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # The template element belongs to the document; its content does not. | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 3 | ▶ | if ($template_depth) { $template_depth++; return } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 4 | } elsif ($template_depth) { return } | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | 10143 | my $loc = $location->($offset, $tag); | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | 10143 | my %values; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 10143 | for my $key (qw(id name href)) { | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | $values{$key} = decode('UTF-8', $attr->{$key}, FB_CROAK) | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 30429 | ▶ | if exists($attr->{$key}) && defined($attr->{$key}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $attr->{$key} and defined $attr->{$key}
MC/DC50%1/2
exists $attr->{$key} and defined $attr->{$key}
exists $attr->{$key}
defined $attr->{$key}
Truth table66%2/3
A and B
A= exists $attr->{$key}B= defined $attr->{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 10143 | ▶ | if (defined($values{id}) && length($values{id})) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $values{"id"} and length $values{"id"}
MC/DC50%1/2
defined $values{"id"} and length $values{"id"}
defined $values{"id"}
length $values{"id"}
Truth table66%2/3
A and B
A= defined $values{"id"}B= length $values{"id"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 5079 | my $target = { kind => 'id', value => $values{id}, %$loc }; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 5079 | ▶ | my $existing = $ids{$values{id}} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$ids{$values{"id"}} ||= []
MC/DC100%1/1
$ids{$values{"id"}} ||= []
$ids{$values{"id"}}
Truth table100%2/2
A
A= $ids{$values{"id"}}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 5079 | ▶ | if (@$existing) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | $add_issue->({ code => 'duplicate_id', value => $values{id}, %$loc, | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 50 | related => [ { %{ $existing->[0] } } ] }); | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 5079 | push @$existing, $target; | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | 5079 | push @targets, $target; | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 5079 | $normalized{NFC($values{id})}{$values{id}} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 10143 | ▶ | if ($tag eq 'a' && defined($values{name}) && length($values{name})) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$tag eq "a" and defined $values{"name"} and length $values{"name"}
$tag eq "a" and defined $values{"name"}
MC/DC66%2/3
$tag eq "a" and defined $values{"name"} and length $values{"name"}
$tag eq "a"
defined $values{"name"}
length $values{"name"}
Truth table75%3/4
A and B and C
A= $tag eq "a"B= defined $values{"name"}C= length $values{"name"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 5 | my $target = { kind => 'name', value => $values{name}, %$loc }; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | 5 | ▶ | push @{ $names{$values{name}} ||= [] }, $target; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$names{$values{"name"}} ||= []
MC/DC100%1/1
$names{$values{"name"}} ||= []
$names{$values{"name"}}
Truth table100%2/2
A
A= $names{$values{"name"}}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 5 | push @targets, $target; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 5 | $normalized{NFC($values{name})}{$values{name}} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 10143 | ▶ | if ($tag eq 'base' && !defined($base_href) && defined($values{href})) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$tag eq "base" and not defined $base_href and defined $values{"href"}
$tag eq "base" and not defined $base_href
MC/DC66%2/3
$tag eq "base" and not defined $base_href and defined $values{"href"}
$tag eq "base"
not defined $base_href
defined $values{"href"}
Truth table75%3/4
A and not(B) and C
A= $tag eq "base"B= not defined $base_hrefC= defined $values{"href"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | my $href = $values{href}; | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | $href =~ s/[\t\r\n]//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | $href =~ s/\A[\x00-\x20]+|[\x00-\x20]+\z//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | $base_href = $href; | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 10143 | ▶ | if (($tag eq 'a' || $tag eq 'area') && defined($values{href})) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$tag eq "a" || $tag eq "area" and defined $values{"href"}
$tag eq "a" or $tag eq "area"
MC/DC100%3/3
$tag eq "a" || $tag eq "area" and defined $values{"href"}
$tag eq "a"
$tag eq "area"
defined $values{"href"}
Truth table80%4/5
A or B and C
A= $tag eq "a"B= $tag eq "area"C= defined $values{"href"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 5050 | my $href = $values{href}; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | 5050 | $href =~ s/[\t\r\n]//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | 5050 | $href =~ s/\A[\x00-\x20]+|[\x00-\x20]+\z//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | 5050 | ▶ | if (substr($href, 0, 1) eq '#') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 5047 | push @refs, { href => $values{href}, fragment => substr($href, 1), %$loc }; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | } else { $out_of_scope++ } | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 10143 | ▶ | $template_depth = 1 if $tag eq 'template'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 46 | }, 'tagname,attr,offset'); | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | 10143 | ▶ | $parser->handler(end => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 10143 | my ($tag) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | 10143 | ▶ | $template_depth-- if $tag eq 'template' && $template_depth; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$tag eq "template" and $template_depth
MC/DC50%1/2
$tag eq "template" and $template_depth
$tag eq "template"
$template_depth
Truth table66%2/3
A and B
A= $tag eq "template"B= $template_depth
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 46 | }, 'tagname'); | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | 46 | $parser->parse($bytes); | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | 46 | $parser->eof; | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 46 | my ($checked, $ignored) = (0, 0); | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | 46 | for my $ref (@refs) { | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | 5047 | ▶ | if (defined($base_href) && length($base_href)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $base_href and length $base_href
MC/DC100%2/2
defined $base_href and length $base_href
defined $base_href
length $base_href
Truth table100%3/3
A and B
A= defined $base_hrefB= length $base_href
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | $ref->{status} = 'ignored'; $ref->{reason} = 'base_href'; $ignored++; next; | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 5046 | ▶ | if (index($ref->{fragment}, ':~:') >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | $ref->{status} = 'ignored'; $ref->{reason} = 'fragment_directive'; $ignored++; next; | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 5045 | $checked++; | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | 5045 | ▶ | if ($ref->{fragment} eq '') { $ref->{status} = 'top'; next } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 5044 | my $escaped = encode('UTF-8', $ref->{fragment}); | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 5044 | $escaped =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | 5044 | my $decoded = decode('UTF-8', $escaped, FB_DEFAULT); | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | 5044 | $ref->{decoded_fragment} = $decoded; | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | 5044 | my ($matches, $matched_value, $matched_kind); | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | 5044 | for my $value ($ref->{fragment}, $decoded) { | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 5068 | ▶ | if ($ids{$value}) { ($matches, $matched_value, $matched_kind) = ($ids{$value}, $value, 'id'); last } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 47 | ▶ | if ($names{$value}) { ($matches, $matched_value, $matched_kind) = ($names{$value}, $value, 'name'); last } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 5044 | ▶ | if ($matches) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 5023 | ▶ | my @related = map { { %$_ } } @$matches[0 .. ($#$matches < 9 ? $#$matches : 9)]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 5023 | ▶ | $ref->{status} = @$matches > 1 ? 'ambiguous' : 'matched'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 5023 | $ref->{target_value} = $matched_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 5023 | $ref->{target_kind} = $matched_kind; | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 5023 | $ref->{target_count} = scalar(@$matches); | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | 5023 | $ref->{targets} = \@related; | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | 5023 | ▶ | if (@$matches > 1) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | $add_issue->({ code => 'ambiguous_target', href => $ref->{href}, value => $matched_value, | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 3 | (map { $_ => $ref->{$_} } qw(tag line column byte_column byte_offset)), | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | related_count => scalar(@$matches), related => \@related }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } elsif ($decoded =~ /\A[Tt][Oo][Pp]\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 3 | $ref->{status} = 'top'; | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 18 | $ref->{status} = 'missing'; | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | 18 | ▶ | my @suggestions = sort keys %{ $normalized{NFC($decoded)} || {} }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$normalized{&NFC($decoded)} || {}
MC/DC100%1/1
$normalized{&NFC($decoded)} || {}
$normalized{&NFC($decoded)}
Truth table100%2/2
A
A= $normalized{&NFC($decoded)}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | my $issue = { code => 'missing_target', href => $ref->{href}, value => $decoded, | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 18 | map { $_ => $ref->{$_} } qw(tag line column byte_column byte_offset) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | 18 | ▶ | $issue->{normalization_candidates} = \@suggestions if @suggestions; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 18 | $add_issue->($issue); | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 46 | ▶ | @issues = sort { $a->{byte_offset} <=> $b->{byte_offset} || $a->{code} cmp $b->{code} } @issues; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$HTML::Anchor::Audit::a->{'byte_offset'} <=> $HTML::Anchor::Audit::b->{'byte_offset'} || $HTML::Anchor::Audit::a->{'code'} cmp $HTML::Anchor::Audit::b->{'code'}
MC/DC0%0/2
$HTML::Anchor::Audit::a->{'byte_offset'} <=> $HTML::Anchor::Audit::b->{'byte_offset'} || $HTML::Anchor::Audit::a->{'code'} cmp $HTML::Anchor::Audit::b->{'code'}
$HTML::Anchor::Audit::a->{'byte_offset'} <=> $HTML::Anchor::Audit::b->{'byte_offset'}
$HTML::Anchor::Audit::a->{'code'} cmp $HTML::Anchor::Audit::b->{'code'}
Truth table33%1/3
A || B
A= $HTML::Anchor::Audit::a->{'byte_offset'} <=> $HTML::Anchor::Audit::b->{'byte_offset'}B= $HTML::Anchor::Audit::a->{'code'} cmp $HTML::Anchor::Audit::b->{'code'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | return { | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 46 | ▶ | schema_version => 1, targets => \@targets, references => \@refs, issues => \@issues, | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | statistics => { target_count => scalar(@targets), reference_count => scalar(@refs), | ||||||||||||||||||||||||||||||||||||||||||||||
| 169 | checked_reference_count => $checked, ignored_reference_count => $ignored, | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | out_of_scope_href_count => $out_of_scope, issue_count => $total_issues, | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | reported_issue_count => scalar(@issues), truncated => $total_issues > @issues ? 1 : 0 }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||