| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Locale::Maketext::Utils::Phrase::Norm::Markup; |
|
2
|
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
2393
|
use strict; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
161
|
|
|
4
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
950
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub normalize_maketext_string { |
|
7
|
79
|
|
|
79
|
0
|
194
|
my ($filter) = @_; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# & is handled more in depth in it's own module |
|
10
|
79
|
100
|
|
|
|
253
|
if ( $filter->get_orig_str() =~ m/[<>"']/ ) { |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# normalize <>"' to [output,ENT] |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# this filter could be smarter like ampersand’s 'Prefer [output,amp] over …' and 'Prefer chr(38) over …' |
|
15
|
|
|
|
|
|
|
|
|
16
|
14
|
|
|
|
|
45
|
my $string_sr = $filter->get_string_sr(); |
|
17
|
|
|
|
|
|
|
|
|
18
|
14
|
100
|
|
|
|
78
|
if ( ${$string_sr} =~ s/'/[output,apos]/g ) { |
|
|
14
|
|
|
|
|
85
|
|
|
19
|
10
|
|
|
|
|
33
|
$filter->add_warning('consider if, instead of using a straight apostrophe, using ‘’ for single quoting and ’ for an apostrophe is the right thing here (i.e. instead of bracket notation)'); |
|
20
|
|
|
|
|
|
|
} |
|
21
|
14
|
50
|
|
|
|
31
|
if ( ${$string_sr} =~ s/"/[output,quot]/g ) { |
|
|
14
|
|
|
|
|
82
|
|
|
22
|
14
|
|
|
|
|
43
|
$filter->add_warning('consider if, instead of using straight double quotes, using “” is the right thing here (i.e. instead of bracket notation)'); |
|
23
|
|
|
|
|
|
|
} |
|
24
|
14
|
|
|
|
|
29
|
${$string_sr} =~ s/>/[output,gt]/g; |
|
|
14
|
|
|
|
|
51
|
|
|
25
|
14
|
|
|
|
|
38
|
${$string_sr} =~ s/</[output,lt]/g; |
|
|
14
|
|
|
|
|
69
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
14
|
|
|
|
|
45
|
$filter->add_violation('Contains markup related characters'); |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
79
|
|
|
|
|
2664
|
return $filter->return_value; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
__END__ |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=encoding utf-8 |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 Normalization |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Turn markup related characters into bracket notation. |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 Rationale |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Allowing markup characters in the phrase is problematic for a number of reasons, including: |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=over 4 |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item * Markup only makes sense in one context. |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item * Their presence could unpredictably break markup or other syntax. |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item * Translators are likely to unwittingly change/break markup unless you take extra precautions (e.g. more <ph> handling of text/html ctype in XLIFF, yikes!). |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item * Markup could also make the translatable part harder for them to translate. |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item * Allowing markup encourages using your phrase as a template/branding/theming system which is a really terrible idea. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item * if we don’t use them, even in chr() it is less problem prone since bracket notation allows to do things correctly in each context |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=back |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
So we detect and modify them. |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 IF YOU USE THIS FILTER ALSO USE … |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
… THIS FILTER L<Locale::Maketext::Utils::Phrase::Norm::Ampersand>. |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
This is not enforced anywhere since we want to assume the coder knows what they are doing. |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 possible violations |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=over 4 |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item Contains markup related characters |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Turns <>'" into appropriate bracket notation. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
& is handled in its own driver. |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=back |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 possible warnings |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=over 4 |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item consider if, instead of using straight double quotes, using “” is the right thing here (i.e. instead of bracket notation) |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This is issued when " is encountered. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item consider if, instead of using a straight apostrophe, using ‘’ for single quoting and ’ for an apostrophe is the right thing here (i.e. instead of bracket notation) |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This is issued when ' is encountered. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=back |