use HTML::Entities qw(decode_entities encode_entities encode_entities_numeric); print "1..11\n"; $a = "Våre norske tegn bør æres"; decode_entities($a); print "ok 1\n" if $a eq "Våre norske tegn bør æres"; encode_entities($a); print "ok 2\n" if $a eq "Våre norske tegn bør æres"; decode_entities($a); encode_entities_numeric($a); print "ok 3\n" if $a eq "Våre norske tegn bør æres"; $a = "<&>"; print "ok 4\n" if encode_entities($a) eq "<&>"; print "ok 5\n" if encode_entities_numeric($a) eq "<&>"; $a = "abcdef"; print "ok 6\n" if encode_entities($a, 'a-c') eq "abcdef"; # See how well it does against rfc1866... $ent = $plain = ""; while () { next unless /^\s*>>>$ent\n>>>>$plain\n"; $a = $ent; decode_entities($a); print "DDD>$a\n"; print "not " if $a ne $plain; print "ok 7\n"; # Try decoding when the ";" are left out $a = $ent, $a =~ s/;//g; decode_entities($a); print ";;;>$a\n"; print "not " if $a ne $plain; print "ok 8\n"; $a = $plain; encode_entities($a); print "EEE>$a\n"; print "not " if $a ne $ent; print "ok 9\n"; # From: Bill Simpson-Young # Subject: HTML entities problem with 5.11 # To: libwww-perl@ics.uci.edu # Date: Fri, 05 Sep 1997 16:56:55 +1000 # Message-Id: <199709050657.QAA10089@snowy.nsw.cmis.CSIRO.AU> # # Hi. I've got a problem that has surfaced with the changes to # HTML::Entities.pm for 5.11 (it doesn't happen with 5.08). It's happening # in the process of encoding then decoding special entities. Eg, what goes # in as "abc&def&ghi" comes out as "abc&def;&ghi;". print "not " unless decode_entities("abc&def&ghi&abc;&def;") eq "abc&def&ghi&abc;&def;"; print "ok 10\n"; # Decoding of ' print "not " unless decode_entities("'") eq "'" && encode_entities("'", "'") eq "'"; print "ok 11\n"; __END__ # Quoted from rfc1866.txt 14. Proposed Entities The HTML DTD references the "Added Latin 1" entity set, which only supplies named entities for a subset of the non-ASCII characters in [ISO-8859-1], namely the accented characters. The following entities should be supported so that all ISO 8859-1 characters may only be referenced symbolically. The names for these entities are taken from the appendixes of [SGML]. Berners-Lee & Connolly Standards Track [Page 75] RFC 1866 Hypertext Markup Language - 2.0 November 1995 Berners-Lee & Connolly Standards Track [Page 76] RFC 1866 Hypertext Markup Language - 2.0 November 1995