File Coverage

blib/lib/Locale/Maketext/Utils/Phrase/Norm/Escapes.pm
Criterion Covered Total %
statement 15 15 100.0
branch 4 4 100.0
condition n/a
subroutine 3 3 100.0
pod 0 1 0.0
total 22 23 95.6


line stmt bran cond sub pod time code
1             package Locale::Maketext::Utils::Phrase::Norm::Escapes;
2              
3 4     4   3229 use strict;
  4         10  
  4         179  
4 4     4   24 use warnings;
  4         8  
  4         1158  
5              
6             sub normalize_maketext_string {
7 79     79 0 212 my ($filter) = @_;
8              
9 79         230 my $string_sr = $filter->get_string_sr();
10              
11             # This will handle previously altered characters like " in the aggregate results
12 79 100       143 if ( ${$string_sr} =~ s/(?:\\\[(.*?)\])/[comment,escaped sequence “~[$1~]”]/g ) { # TODO: make the \[.*?\] regex/logic smarter since it will not work with ~[ but why would we do that right :) - may need to wait for phrase-as-class obj
  79         353  
13 2         11 $filter->add_violation('Contains escape sequence');
14             }
15              
16 79 100       193 if ( ${$string_sr} =~ s/(?:\\([^NUuxX]))/[comment,escaped sequence “$1”]/g ) {
  79         405  
17 10         43 $filter->add_violation('Contains escape sequence');
18             }
19              
20 79         234 return $filter->return_value;
21             }
22              
23             1;
24              
25             __END__
26              
27             =encoding utf-8
28              
29             =head1 Normalization
30              
31             Detect escaped character sequences.
32              
33             =head2 Rationale
34              
35             An escaped character:
36              
37             =over 4
38              
39             =item * adds ambiguity
40              
41             =item * is an indication of in-string-formatting (e.g. \n)
42              
43             =item * relies on interpolation
44              
45             The additional layer of complexity could hinder translators and thus makes room for lower quality translations.
46              
47             Also, among other things, it could make key lookup erroneously fail.
48              
49             =item * Indicates use of a markup character (e.g. "You are \"awesome\".") which should be done differently (e.g. since that is will break the syntax if used in an HTML tag title attribute).
50              
51             =back
52              
53             =head1 possible violations
54              
55             If you get false positives then that only goes to help highlight how ambiguity adds to the reason to avoid non-bytes strings!
56              
57             =over 4
58              
59             =item Contains escape sequence
60              
61             A sequence of \n will be replaced w/ [comment,escaped sequence “n”], \" [comment,escaped sequence “"”], etc
62              
63             =back
64              
65             =head1 possible warnings
66              
67             None