Skip to content
Browse files

Fixed external entity handling on MacOS.

Also made small change to the test suite to be cleaner.
  • Loading branch information...
1 parent 72e77f3 commit ed371c566925c1fff75c1abe26844e5ab3b16e50 @rjray committed
Showing with 24 additions and 6 deletions.
  1. +23 −5 lib/RPC/XML/Parser/XMLLibXML.pm
  2. +1 −1 t/21_xml_libxml.t
View
28 lib/RPC/XML/Parser/XMLLibXML.pm
@@ -94,12 +94,30 @@ sub parse
no_network => 1,
expand_xinclude => 0,
expand_entities => 1,
- load_ext_dtd => 0,
- ext_ent_handler => sub {
- warn "External entities disabled.\n";
- return q{}
- },
+ load_ext_dtd => 0
);
+ # I really don't need the full granularity of XML::LibXML::InputCallback
+ # here, but the ext_ent_handler was not working with the version of
+ # libxml2 on Apple's Snow Leopard.
+ my $callbacks = XML::LibXML::InputCallback->new();
+ $callbacks->register_callbacks([
+ sub {
+ my ($uri) = @_;
+ if ($uri =~ m{^file:/})
+ {
+ warn "External entities disabled.\n";
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+ },
+ sub {},
+ sub {},
+ sub {},
+ ]);
+ $parser->input_callbacks($callbacks);
# RT58323: It's not enough to just test $stream, I have to check
# defined-ness. A 0 or null-string should yield an error, not a push-parser
View
2 t/21_xml_libxml.t
@@ -162,6 +162,6 @@ EOX
$pp = RPC::XML::Parser::XMLLibXML->new->parse();
$ret = $pp->parse($bad_entities);
my $args = $ret->args;
-is $args->[0]->value, 'Entity test: ', "bad entities ignored";
+is($args->[0]->value, 'Entity test: ', 'Bad entities ignored');
exit 0;

0 comments on commit ed371c5

Please sign in to comment.
Something went wrong with that request. Please try again.