| 1 | package Net::OpenID::JanRain::Consumer::LinkParser; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use Exporter; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||
| 6 | 1 | our @EXPORT_OK = qw(parseLinkAttrs parseOpenIDLinkRel); | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 1 | my $htmlre = qr{ | |||||||||||||||||||
| 9 | # Starts with the tag name at a word boundary, where the tag name is | ||||||||||||||||||||
| 10 | # not a namespace | ||||||||||||||||||||
| 11 | <html\b(?!:) | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | # All of the stuff up to a ">", hopefully attributes. | ||||||||||||||||||||
| 14 | ([^>]*?) | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | (?: # Match a short tag | ||||||||||||||||||||
| 17 | /> | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | | # Match a full tag | ||||||||||||||||||||
| 20 | > | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | # contents | ||||||||||||||||||||
| 23 | (.*?) | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | # Closed by | ||||||||||||||||||||
| 26 | (?: # One of the specified close tags | ||||||||||||||||||||
| 27 | </?html\s*> | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | # End of the string | ||||||||||||||||||||
| 30 | | \Z | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | ) | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | ) | ||||||||||||||||||||
| 35 | }soxi; | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 1 | my $headre = qr{ | |||||||||||||||||||
| 38 | # Starts with the tag name at a word boundary, where the tag name is | ||||||||||||||||||||
| 39 | # not a namespace | ||||||||||||||||||||
| 40 | <head\b(?!:) | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | # All of the stuff up to a ">", hopefully attributes. | ||||||||||||||||||||
| 43 | ([^>]*?) | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | (?: # Match a short tag | ||||||||||||||||||||
| 46 | /> | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | | # Match a full tag | ||||||||||||||||||||
| 49 | > | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | # match the contents of the full tag | ||||||||||||||||||||
| 52 | (.*?) | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | # Closed by | ||||||||||||||||||||
| 55 | (?: # One of the specified close tags | ||||||||||||||||||||
| 56 | </?(?:head|body)\s*> | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | # End of the string | ||||||||||||||||||||
| 59 | | \Z | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | ) | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | ) | ||||||||||||||||||||
| 64 | }isox; | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 1 | my $linkre = qr{ | |||||||||||||||||||
| 67 | <link\b(?!:) | ||||||||||||||||||||
| 68 | ([^<>]*[^<>/]) | ||||||||||||||||||||
| 69 | /?>? | ||||||||||||||||||||
| 70 | }six; | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 1 | my $attrre = qr{ | |||||||||||||||||||
| 74 | # Must start with a sequence of word-characters, followed by an equals sign | ||||||||||||||||||||
| 75 | (\w+)= | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | # Then either a quoted or unquoted attribute | ||||||||||||||||||||
| 78 | (?: | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | # Match everything that is between matching quote marks | ||||||||||||||||||||
| 81 | (["'])(.*?)\2 | ||||||||||||||||||||
| 82 | | | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | # If the value is not quoted, match up to whitespace | ||||||||||||||||||||
| 85 | ([^"'\s]+) | ||||||||||||||||||||
| 86 | ) | ||||||||||||||||||||
| 87 | }sx; | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 1 | my $removere = qr{ | |||||||||||||||||||
| 90 | # Comments | ||||||||||||||||||||
| 91 | <!--.*?--> | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | # CDATA blocks | ||||||||||||||||||||
| 94 | | <!\[CDATA\[.*?\]\]> | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | # script blocks | ||||||||||||||||||||
| 97 | | <script\b | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | # make sure script is not an XML namespace | ||||||||||||||||||||
| 100 | (?!:) | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | [^>]*>.*?</script> | ||||||||||||||||||||
| 103 | }soix; | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 1 | my %replacements = ( | |||||||||||||||||||
| 106 | 'amp' => '&', | ||||||||||||||||||||
| 107 | 'lt' => '<', | ||||||||||||||||||||
| 108 | 'gt' => '>', | ||||||||||||||||||||
| 109 | 'quot' => '"', | ||||||||||||||||||||
| 110 | ); | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 73 | ▶ | sub parseLinkAttrs { | ||||||||||||||||||
|
Subroutine
parseLinkAttrs: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||
| 113 | 73 | my ($html) = @_; | |||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 73 | $html =~ s/$removere//; | |||||||||||||||||||
| 116 | 73 | ▶ | $html =~ $htmlre or return (); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 117 | 71 | my $htmlcontents = $2; | |||||||||||||||||||
| 118 | 71 | ▶ | $htmlcontents =~ $headre or return (); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 119 | 69 | my $head = $2; | |||||||||||||||||||
| 120 | 69 | ▶ | defined $head or return (); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | 67 | my @linkhashes; | |||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | 67 | foreach my $linktag ($head =~ /$linkre/g) { | |||||||||||||||||||
| 125 | 40 | my %linkhash; | |||||||||||||||||||
| 126 | 40 | ▶ | while ($linktag =~ /$attrre/g) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 127 | 47 | ▶ | my ($k,$v) = ($1, $3 || $4); | ||||||||||||||||||
|
Condition66%2/3
$3 || $4
MC/DC0%0/2
$3 || $4
$3
$4
Truth table66%2/3
A || B
A= $3B= $4
| |||||||||||||||||||||
| 128 | 47 | for my $pat (keys %replacements) { | |||||||||||||||||||
| 129 | 188 | $k =~ s/&$pat;/$replacements{$pat}/g; | |||||||||||||||||||
| 130 | 188 | $v =~ s/&$pat;/$replacements{$pat}/g; | |||||||||||||||||||
| 131 | } | ||||||||||||||||||||
| 132 | 47 | $linkhash{lc($k)}=$v; | |||||||||||||||||||
| 133 | } | ||||||||||||||||||||
| 134 | 40 | push @linkhashes, \%linkhash; | |||||||||||||||||||
| 135 | } | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 67 | return @linkhashes; | |||||||||||||||||||
| 138 | } | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 0 | ▶ | sub parseOpenIDLinkRel { | ||||||||||||||||||
|
Subroutine
parseOpenIDLinkRel: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 141 | 0 | my $html = shift; | |||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | 0 | my @linkhashes = parseLinkAttrs($html); | |||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | 0 | my ($server, $delegate); | |||||||||||||||||||
| 146 | 0 | for my $link (@linkhashes) { | |||||||||||||||||||
| 147 | 0 | ▶ | if (lc($link->{rel}) eq 'openid.server') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 148 | 0 | my %foo = %$link; | |||||||||||||||||||
| 149 | 0 | $server = $link->{href}; | |||||||||||||||||||
| 150 | } | ||||||||||||||||||||
| 151 | 0 | ▶ | if (lc($link->{rel}) eq 'openid.delegate') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 152 | 0 | $delegate = $link->{href}; | |||||||||||||||||||
| 153 | } | ||||||||||||||||||||
| 154 | } | ||||||||||||||||||||
| 155 | 0 | return ($delegate, $server); | |||||||||||||||||||
| 156 | } | ||||||||||||||||||||