line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package URI::_idna; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# This module implements the RFCs 3490 (IDNA) and 3491 (Nameprep) |
4
|
|
|
|
|
|
|
# based on Python-2.6.4/Lib/encodings/idna.py |
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
71524
|
use strict; |
|
3
|
|
|
|
|
17
|
|
|
3
|
|
|
|
|
95
|
|
7
|
3
|
|
|
3
|
|
38
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
111
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
1368
|
use URI::_punycode qw(decode_punycode encode_punycode); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
210
|
|
10
|
3
|
|
|
3
|
|
25
|
use Carp qw(croak); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
364
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '5.20'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
BEGIN { |
15
|
|
|
|
|
|
|
*URI::_idna::_ENV_::JOIN_LEAKS_UTF8_FLAGS = "$]" < 5.008_003 |
16
|
|
|
|
|
|
|
? sub () { 1 } |
17
|
|
|
|
|
|
|
: sub () { 0 } |
18
|
3
|
50
|
|
3
|
|
1893
|
; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $ASCII = qr/^[\x00-\x7F]*\z/; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub encode { |
24
|
9
|
|
|
9
|
0
|
115
|
my $idomain = shift; |
25
|
9
|
|
|
|
|
36
|
my @labels = split(/\./, $idomain, -1); |
26
|
9
|
|
|
|
|
18
|
my @last_empty; |
27
|
9
|
100
|
100
|
|
|
45
|
push(@last_empty, pop @labels) if @labels > 1 && $labels[-1] eq ""; |
28
|
9
|
|
|
|
|
19
|
for (@labels) { |
29
|
19
|
|
|
|
|
39
|
$_ = ToASCII($_); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
8
|
|
|
|
|
11
|
return eval 'join(".", @labels, @last_empty)' if URI::_idna::_ENV_::JOIN_LEAKS_UTF8_FLAGS; |
33
|
8
|
|
|
|
|
45
|
return join(".", @labels, @last_empty); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub decode { |
37
|
12
|
|
|
12
|
0
|
23
|
my $domain = shift; |
38
|
12
|
|
|
|
|
46
|
return join(".", map ToUnicode($_), split(/\./, $domain, -1)) |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub nameprep { # XXX real implementation missing |
42
|
17
|
|
|
17
|
0
|
22
|
my $label = shift; |
43
|
17
|
|
|
1
|
|
71
|
$label = lc($label); |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
44
|
17
|
|
|
|
|
28046
|
return $label; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub check_size { |
48
|
29
|
|
|
29
|
0
|
53
|
my $label = shift; |
49
|
29
|
50
|
|
|
|
57
|
croak "Label empty" if $label eq ""; |
50
|
29
|
100
|
|
|
|
347
|
croak "Label too long" if length($label) > 63; |
51
|
28
|
|
|
|
|
73
|
return $label; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub ToASCII { |
55
|
29
|
|
|
29
|
0
|
41
|
my $label = shift; |
56
|
29
|
100
|
|
|
|
181
|
return check_size($label) if $label =~ $ASCII; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Step 2: nameprep |
59
|
17
|
|
|
|
|
40
|
$label = nameprep($label); |
60
|
|
|
|
|
|
|
# Step 3: UseSTD3ASCIIRules is false |
61
|
|
|
|
|
|
|
# Step 4: try ASCII again |
62
|
17
|
50
|
|
|
|
77
|
return check_size($label) if $label =~ $ASCII; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Step 5: Check ACE prefix |
65
|
17
|
50
|
|
|
|
44
|
if ($label =~ /^xn--/) { |
66
|
0
|
|
|
|
|
0
|
croak "Label starts with ACE prefix"; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Step 6: Encode with PUNYCODE |
70
|
17
|
|
|
|
|
40
|
$label = encode_punycode($label); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Step 7: Prepend ACE prefix |
73
|
17
|
|
|
|
|
44
|
$label = "xn--$label"; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Step 8: Check size |
76
|
17
|
|
|
|
|
37
|
return check_size($label); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub ToUnicode { |
80
|
29
|
|
|
29
|
0
|
49
|
my $label = shift; |
81
|
29
|
50
|
|
|
|
158
|
$label = nameprep($label) unless $label =~ $ASCII; |
82
|
29
|
100
|
|
|
|
129
|
return $label unless $label =~ /^xn--/; |
83
|
10
|
|
|
|
|
36
|
my $result = decode_punycode(substr($label, 4)); |
84
|
10
|
|
|
|
|
28
|
my $label2 = ToASCII($result); |
85
|
10
|
50
|
|
|
|
40
|
if (lc($label) ne $label2) { |
86
|
0
|
|
|
|
|
0
|
croak "IDNA does not round-trip: '\L$label\E' vs '$label2'"; |
87
|
|
|
|
|
|
|
} |
88
|
10
|
|
|
|
|
27
|
return $result; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |