Permalink
Browse files

Implement sane default parse options

  • Loading branch information...
1 parent deaafc9 commit 2a3713befd2d622b8fcf621a4f68ccb09f892b58 @yannk yannk committed with miyagawa Jun 8, 2011
Showing with 32 additions and 6 deletions.
  1. +20 −0 lib/XML/Atom.pm
  2. +3 −1 lib/XML/Atom/Client.pm
  3. +3 −1 lib/XML/Atom/Server.pm
  4. +6 −4 lib/XML/Atom/Thing.pm
View
@@ -35,6 +35,26 @@ BEGIN {
$XML::Atom::DefaultVersion = 0.3;
}
+sub libxml_parser {
+ ## uses old XML::LibXML < 1.70 interface for compat reasons
+ return XML::LibXML->new(
+ #no_network => 1, # v1.63+
+ expand_xinclude => 0,
+ expand_entities => 1,
+ load_ext_dtd => 0,
+ ext_ent_handler => sub { warn "External entities disabled."; '' },
+ );
+}
+
+sub expat_parser {
+ return XML::Parser->new(
+ Handlers => {
+ ExternEnt => sub { warn "External Entities disabled."; '' },
+ ExternEntFin => sub {},
+ },
+ );
+}
+
use base qw( XML::Atom::ErrorHandler Exporter );
package XML::Atom::Namespace;
@@ -188,7 +188,7 @@ sub munge_response {
if ($client->use_soap && (my $xml = $res->content)) {
my $doc;
if (LIBXML) {
- my $parser = XML::LibXML->new;
+ my $parser = $client->libxml_parser;
$doc = $parser->parse_string($xml);
} else {
my $xp = XML::XPath->new(xml => $xml);
@@ -218,6 +218,8 @@ sub _utf8_off {
}
}
+sub libxml_parser { XML::Atom->libxml_parser }
+
package LWP::UserAgent::AtomClient;
use strict;
use Scalar::Util;
@@ -284,7 +284,7 @@ sub xml_body {
my $server = shift;
unless (exists $server->{xml_body}) {
if (LIBXML) {
- my $parser = XML::LibXML->new;
+ my $parser = $server->libxml_parser;
$server->{xml_body} =
$parser->parse_string($server->request_content);
} else {
@@ -309,6 +309,8 @@ sub atom_body {
$atom;
}
+sub libxml_parser { XML::Atom->libxml_parser }
+
1;
__END__
View
@@ -22,7 +22,7 @@ sub init_libxml {
my $atom = shift;
my %param = @_ == 1 ? (Stream => $_[0]) : @_;
if (my $stream = delete $param{Stream}) {
- my $parser = XML::LibXML->new;
+ my $parser = delete $param{Parser} || XML::Atom->libxml_parser;
my $doc;
if (ref($stream) eq 'SCALAR') {
$doc = $parser->parse_string($$stream);
@@ -50,14 +50,16 @@ sub init_xpath {
my %param = @_ == 1 ? (Stream => $_[0]) : @_;
my $elem_name = $atom->element_name;
if (my $stream = delete $param{Stream}) {
+ my $parser = delete $param{Parser} || XML::Atom->expat_parser;
my $xp;
if (ref($stream) eq 'SCALAR') {
- $xp = XML::XPath->new(xml => $$stream);
+ $xp = XML::XPath->new(xml => $$stream, parser => $parser);
} elsif (ref($stream)) {
- $xp = XML::XPath->new(ioref => $stream);
+ $xp = XML::XPath->new(ioref => $stream, parser => $parser);
} else {
- $xp = XML::XPath->new(filename => $stream);
+ $xp = XML::XPath->new(filename => $stream, parser => $parser);
}
+ $DB::single = 1;
my $set = $xp->find('/' . $elem_name);
unless ($set && $set->size) {
$set = $xp->find('/');

0 comments on commit 2a3713b

Please sign in to comment.