Skip to content

Commit 6f9b522

Browse files
committed
Pod::Simple::XHTML: better fallback when HTML::Entities isn't installed
This commit changes the default set of escaped characters in the fallback code to be the same as in HTML::Entities. Fixes #188
1 parent 0019223 commit 6f9b522

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

lib/Pod/Simple/XHTML.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ sub encode_entities {
7070
$ents =~ s,(?<!\\)([]/]),\\$1,g;
7171
$ents =~ s,(?<!\\)\\\z,\\\\,;
7272
} else {
73-
$ents = join '', keys %entities;
73+
# the same set of characters as in HTML::Entities
74+
$ents = '^\n\r\t !\#\$%\(-;=?-~';
7475
}
7576
my $str = $_[0];
76-
$str =~ s/([$ents])/'&' . ($entities{$1} || sprintf '#x%X', ord $1) . ';'/ge;
77+
$str =~ s/([$ents])/'&' . ($entities{$1} || sprintf '#x%X', unpack('U', $1)) . ';'/ge;
7778
return $str;
7879
}
7980

t/xhtml01.t

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# t/xhtml01.t - check basic output from Pod::Simple::XHTML
22
use strict;
33
use warnings;
4-
use Test::More tests => 66;
4+
use Test::More tests => 68;
55

66
use_ok('Pod::Simple::XHTML') or exit;
77

@@ -712,7 +712,7 @@ is($results, "$html\n\n", "Text with =begin html");
712712

713713
SKIP: for my $use_html_entities (0, 1) {
714714
if ($use_html_entities and not $Pod::Simple::XHTML::HAS_HTML_ENTITIES) {
715-
skip("HTML::Entities not installed", 3);
715+
skip("HTML::Entities not installed", 4);
716716
}
717717
local $Pod::Simple::XHTML::HAS_HTML_ENTITIES = $use_html_entities;
718718
initialize($parser, $results);
@@ -751,11 +751,28 @@ EOHTML
751751
# Keep =encoding out of content.
752752
initialize($parser, $results);
753753
$parser->parse_string_document("=encoding ascii\n\n=head1 NAME\n");
754-
is($results, <<"EOHTML", 'Encoding should not be in content')
754+
is($results, <<"EOHTML", 'Encoding should not be in content');
755755
<h1 id="NAME">NAME</h1>
756756
757757
EOHTML
758758

759+
initialize($parser, $results);
760+
$parser->parse_string_document(<<"EOPOD");
761+
=pod
762+
763+
=encoding UTF-8
764+
765+
The pilcrow, ¶, is used to mark the beginning of a new paragraph.
766+
767+
=cut
768+
769+
EOPOD
770+
771+
$T = $use_html_entities ? '&para;' : '&#xB6;';
772+
is($results, <<"EOHTML", 'Non-ASCII characters are escaped')
773+
<p>The pilcrow, ${T}, is used to mark the beginning of a new paragraph.</p>
774+
775+
EOHTML
759776
}
760777

761778

0 commit comments

Comments
 (0)