• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DrHyde / perl-modules-XML-DoubleEncodedEntities / 7376949840

01 Jan 2024 11:19AM UTC coverage: 100.0%. Remained the same
7376949840

Pull #16

github

web-flow
Bump cross-platform-actions/action from 0.21.1 to 0.22.0

Bumps [cross-platform-actions/action](https://github.com/cross-platform-actions/action) from 0.21.1 to 0.22.0.
- [Release notes](https://github.com/cross-platform-actions/action/releases)
- [Changelog](https://github.com/cross-platform-actions/action/blob/master/changelog.md)
- [Commits](https://github.com/cross-platform-actions/action/compare/v0.21.1...v0.22.0)

---
updated-dependencies:
- dependency-name: cross-platform-actions/action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #16: Bump cross-platform-actions/action from 0.21.1 to 0.22.0

7 of 7 relevant lines covered (100.0%)

4.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/lib/XML/DoubleEncodedEntities.pm
1
package XML::DoubleEncodedEntities;
2

3
use strict;
1✔
4

5
require Exporter;
6

7
use vars qw($VERSION @EXPORT_OK @ISA);
1✔
8

9
$VERSION = '1.1';
10
@EXPORT_OK = qw(decode);
11
@ISA = qw(Exporter);
12

13
# localising prevents the warningness leaking out of this module
14
local $^W = 1;    # can't use warnings as that's a 5.6-ism
15

16
=encoding ISO8859-1
17

18
=head1 NAME
19

20
XML::DoubleEncodedEntities - unbreak XML with doubly-encoded entities
21

22
=head1 DESCRIPTION
23

24
Occasionally, XML files escape into the wild with their entities encoded
25
twice so instead of this:
26

27
    <chocolate>Green &amp; Blacks</chocolate>
28

29
you get:
30

31
    &lt;chocolate&gt;Green &amp;amp; Blacks&lt;/chocolate&gt;
32

33
A real-world example of this problem can be seen in this failing test
34
for a module which queries an online XML datasource:
35

36
    http://www.nntp.perl.org/group/perl.cpan.testers/2007/02/msg414642.html
37

38
(search for the text 'Arcturus' in that page).
39

40
This module tries to fix that.
41

42
=head1 SYNOPSIS
43

44
    use XML::DoubleEncodedEntities;
45
    
46
    my $xmlfile = XML::DoubleEncodedEntities::decode($xmlfile);
47

48
=head1 Functions
49

50
=head2 decode
51

52
This function is not exported, but can be if you wish.  It takes one
53
scalar parameter and returns a corresponding scalar, decoded if necessary.
54

55
The parameter is assumed to be a string.  If its first non-whitespace
56
characters are C<&lt;>, or if it contains the sequence C<&amp;amp;> the
57
string is assumed to be a doubly-encoded XML document, in which case the
58
following entities, if present, are decoded:
59
    &amp;
60
    &lt;
61
    &gt;
62
    &quot;
63
    &apos;
64

65
No other parameters are decoded.  After all, if the input document has been
66
*doubly* encoded then something like C<æ>, which should be the entity C<&aelig;>
67
will be represented by the character sequence C<&amp;aelig;>.  Once the
68
C<&amp;> has been corrected by this module, you'll be able to decode the
69
resulting C<&aelig;> in the normal way.
70

71
=cut
72

73
# ripped off (and simplified) from XML::Tiny
74
sub decode {
75
    my $thingy = shift;
6✔
76
    return $thingy unless($thingy =~ /(^\s*&lt;|&amp;amp;)/);
6✔
77

78
    $thingy =~ s/&(lt;|gt;|quot;|apos;|amp;|.*)/
4✔
79
        $1 eq 'lt;'   ? '<' :
8✔
80
        $1 eq 'gt;'   ? '>' :
81
        $1 eq 'apos;' ? "'" :
82
        $1 eq 'quot;' ? '"' :
83
        $1 eq 'amp;'  ? '&' :
84
        die("Illegal ampersand or entity\n\tat &$1\n")
85
    /ge;
86
    $thingy;
3✔
87
}
88

89
=head1 BUGS and FEEDBACK
90

91
I welcome feedback about my code, including constructive criticism.
92
Bug reports should be made on Github or by email.
93
They should include the smallest possible chunk of code, along with
94
any necessary data, which demonstrates the bug.  Ideally, this
95
will be in the form of a file which I can drop in to the module's
96
test suite.  Ideally such files will work in perl 5.004.
97

98
If you are feeling particularly generous you can encourage me in my
99
open source endeavours by buying me something from my wishlist:
100
  L<http://www.cantrell.org.uk/david/wishlist/>
101

102
=head1 SEE ALSO
103

104
L<Encode::DoubleEncodedUTF8>, which does the same job for broken UTF-8.
105

106
L<Test::DoubleEncodedEntities>, which is HTMLish.
107

108
=head1 AUTHOR
109

110
David Cantrell E<lt>F<david@cantrell.org.uk>E<gt>
111

112
=head1 COPYRIGHT and LICENCE
113

114
Copyright 2007 David Cantrell
115

116
This module is free-as-in-speech software, and may be used, distributed,
117
and modified under the same terms as Perl itself.
118

119
=head1 CONSPIRACY
120

121
This module is also free-as-in-mason software.
122

123
=cut
124

125
'&amp;amp;#49'
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc