line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::Liberal::Remedy::EntityRef; |
2
|
2
|
|
|
2
|
|
987
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
440
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
sub apply { |
5
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
6
|
0
|
|
|
|
|
|
my($driver, $error, $xml_ref) = @_; |
7
|
|
|
|
|
|
|
|
8
|
0
|
0
|
|
|
|
|
return 0 if $error->message !~ |
9
|
|
|
|
|
|
|
/^parser error : (?:EntityRef: expecting ';'|xmlParseEntityRef: no name)/; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# If the document doesn't contain any PIs or CDATA sections, we might as |
12
|
|
|
|
|
|
|
# well try to fix all broken entity references and named character |
13
|
|
|
|
|
|
|
# references in one go. (If it does contain one of those, fixing |
14
|
|
|
|
|
|
|
# everything would risk changing the content in ways the author wouldn't |
15
|
|
|
|
|
|
|
# expect.) |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# In principle, we should take care not to change comments either; but |
18
|
|
|
|
|
|
|
# in practice, I'm prepared to consider comments fair game, given that |
19
|
|
|
|
|
|
|
# the author can preserve them by merely generating a well-formed XML |
20
|
|
|
|
|
|
|
# document. |
21
|
0
|
0
|
|
|
|
|
if ($$xml_ref !~ / .<\? |
|
22
|
0
|
0
|
|
|
|
|
return 1 if $$xml_ref =~ |
23
|
|
|
|
|
|
|
s/&(?!\w+;|#(?:x[a-fA-F0-9]+|\d+);)/&/g; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
else { |
26
|
0
|
|
|
|
|
|
my $pos = $error->location; |
27
|
0
|
|
|
|
|
|
while ($pos > 0) { |
28
|
0
|
|
|
|
|
|
pos($$xml_ref) = $pos--; |
29
|
0
|
0
|
|
|
|
|
return 1 if $$xml_ref =~ s/\G&/&/ |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
Carp::carp("Can't find unescaped &, error was: ", $error->summary); |
34
|
0
|
|
|
|
|
|
return 0; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |