Revision history for Perl extension XML::LibXML
+2.0209 2023-07-15
+ - t/35huge_mode.t: fix test with libxml2 2.11
+ - thanks to Dominique Martinet
+ - Add clearer reference to using cloneNode to extract node with namespaces
+ - thanks to Timothy Legge
+ - initialize xmlValidCtxt
+ - thanks to Alexander Bluhm
+
+2.0208 2022-09-30
+ - Fix https://rt.cpan.org/Ticket/Display.html?id=144415
+ - Bug #144415 for XML-LibXML: createElementNS & setNamespace get
+ confused by Readonly scalars
+ - thanks to DAKKAR and haarg.
+
2.0207 2021-04-17
- Small cleanups:
- https://github.com/shlomif/perl-XML-LibXML/pull/63
use IO::Handle; # for FH reads called as methods
BEGIN {
-$VERSION = "2.0207"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0209"; # VERSION TEMPLATE: DO NOT CHANGE
$ABI_VERSION = 2;
require Exporter;
use XSLoader ();
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
CODE:
INIT_ERROR_HANDLER;
+ memset(&cvp, 0, sizeof(cvp));
cvp.userData = saved_error;
cvp.error = (xmlValidityErrorFunc)LibXML_validity_error_ctx;
cvp.warning = (xmlValidityWarningFunc)LibXML_validity_warning_ctx;
- /* we need to initialize the node stack, because perl might
- * already have messed it up.
- */
- cvp.nodeNr = 0;
- cvp.nodeTab = NULL;
- cvp.vstateNr = 0;
- cvp.vstateTab = NULL;
-
PmmClearPSVI(self);
PmmInvalidatePSVI(self);
if (items > 1) {
CODE:
INIT_ERROR_HANDLER;
+ memset(&cvp, 0, sizeof(cvp));
cvp.userData = saved_error;
cvp.error = (xmlValidityErrorFunc)LibXML_validity_error_ctx;
cvp.warning = (xmlValidityWarningFunc)LibXML_validity_warning_ctx;
- /* we need to initialize the node stack, because perl might
- * already have messed it up.
- */
- cvp.nodeNr = 0;
- cvp.nodeTab = NULL;
- cvp.vstateNr = 0;
- cvp.vstateTab = NULL;
PmmClearPSVI(self);
PmmInvalidatePSVI(self);
CODE:
/* if ( !nsURI ){
XSRETURN_UNDEF;
- } */
+ } */
nsPrefix = nodeSv2C(namespacePrefix, node);
if ( xmlStrlen( nsPrefix ) == 0 ) {
nsURI = NULL;
}
if ( nsPrefix == NULL && nsURI == NULL ) {
- /* special case: empty namespace */
- if ( (ns = xmlSearchNs(node->doc, node, NULL)) &&
- ( ns->href && xmlStrlen( ns->href ) != 0 ) ) {
- /* won't take it */
- RETVAL = 0;
- } else if ( flag ) {
- /* no namespace */
- xmlSetNs(node, NULL);
- RETVAL = 1;
- } else {
- RETVAL = 0;
- }
- }
+ /* special case: empty namespace */
+ if ( (ns = xmlSearchNs(node->doc, node, NULL)) &&
+ ( ns->href && xmlStrlen( ns->href ) != 0 ) ) {
+ /* won't take it */
+ RETVAL = 0;
+ } else if ( flag ) {
+ /* no namespace */
+ xmlSetNs(node, NULL);
+ RETVAL = 1;
+ } else {
+ RETVAL = 0;
+ }
+ }
else if ( flag && (ns = xmlSearchNs(node->doc, node, nsPrefix)) ) {
- /* user just wants to set the namespace for the node */
- /* try to reuse an existing declaration for the prefix */
+ /* user just wants to set the namespace for the node */
+ /* try to reuse an existing declaration for the prefix */
if ( xmlStrEqual( ns->href, nsURI ) ) {
RETVAL = 1;
}
}
}
else if ( (ns = xmlNewNs( node, nsURI, nsPrefix )) )
- RETVAL = 1;
- else
- RETVAL = 0;
+ RETVAL = 1;
+ else
+ RETVAL = 0;
if ( flag && ns ) {
xmlSetNs(node, ns);
t/lib/Counter.pm
t/lib/Stacker.pm
t/lib/TestHelpers.pm
+t/namespace-magic-scalar-rt144415.t
t/pod-files-presence.t
t/pod.t
t/release-kwalitee.t
"Petr Pajas <PAJAS@cpan.org>"
],
"dynamic_config" : 0,
- "generated_by" : "ExtUtils::MakeMaker version 7.60, CPAN::Meta::Converter version 2.150010",
+ "generated_by" : "ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010",
"keywords" : [
"dom",
"html",
"web" : "https://github.com/shlomif/perl-XML-LibXML"
}
},
- "version" : "2.0207",
- "x_serialization_backend" : "JSON::PP version 4.06"
+ "version" : "2.0209",
+ "x_serialization_backend" : "JSON::PP version 4.16"
}
Config: '0'
ExtUtils::MakeMaker: '0'
dynamic_config: 0
-generated_by: 'ExtUtils::MakeMaker version 7.60, CPAN::Meta::Converter version 2.150010'
+generated_by: 'ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010'
keywords:
- dom
- html
warnings: '0'
resources:
repository: https://github.com/shlomif/perl-XML-LibXML.git
-version: '2.0207'
+version: '2.0209'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
"warnings" => 0,
);
-my %xsbuild = (
+my %xsbuild_concat = (
DEFINE => '-DHAVE_UTF8',
OBJECT => '$(O_FILES)',
- Alien::Base::Wrapper->mm_args,
);
+my %xsbuild = Alien::Base::Wrapper->mm_args; # Might contain a definition of DEFINE, must thus concatenate.
+while (my ($k, $v) = each %xsbuild_concat) {
+ my $base_val = $xsbuild{$k};
+ $xsbuild{$k} = (defined($base_val) ? ($base_val . ' ' . $v) : $v);
+}
my %WriteMakefileArgs = (
"NAME" => "XML::LibXML",
</authorgroup>
- <edition>2.0207</edition>
+ <edition>2.0209</edition>
<copyright>
<year>2001-2007</year>
<holder>AxKit.com Ltd</holder>
</funcsynopsis>
<para><emphasis>toStringHTML</emphasis> serialize the tree to a byte string in the document encoding as HTML. With this method indenting is automatic and managed by
- libxml2 internally.</para>
+ libxml2 internally. Note the string must contain
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> (rather than the newer <meta charset="utf-8">),
+ else all non-ASCII will become entities.</para>
</listitem>
</varlistentry>
has changed in 1.62 in order to be consistent with the DOM spec
(in older versions attributes and namespace information
was not copied for elements).</para>
+ <para><emphasis>NOTE</emphasis>cloneNode creates
+ a copy of the selected node that includes the parent's
+ defined <emphasis>namespaces</emphasis> that are in
+ use by the node (or its children) being cloned. That
+ makes it useful for extracting a fragment of xml that
+ can be used as a valid xml document.
+ </para>
</listitem>
</varlistentry>
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
our @ISA = qw/Tie::Hash/;
use vars qw($VERSION);
-$VERSION = "2.0207"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0209"; # VERSION TEMPLATE: DO NOT CHANGE
BEGIN
{
use vars qw ($VERSION);
-$VERSION = "2.0207"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0209"; # VERSION TEMPLATE: DO NOT CHANGE
use overload
'""' => \&value,
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
@ISA = qw(Exporter);
-$VERSION = "2.0207"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0209"; # VERSION TEMPLATE: DO NOT CHANGE
use XML::LibXML qw(:libxml);
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
use XML::LibXML;
use vars qw ($VERSION);
-$VERSION = "2.0207"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0209"; # VERSION TEMPLATE: DO NOT CHANGE
use 5.008_000;
$str = $document->toStringHTML();
I<<<<<< toStringHTML >>>>>> serialize the tree to a byte string in the document encoding as HTML. With this
-method indenting is automatic and managed by libxml2 internally.
+method indenting is automatic and managed by libxml2 internally. Note the
+string must contain <meta http-equiv="Content-Type" content="text/html;
+charset=utf-8"> (rather than the newer <meta charset="utf-8">), else all
+non-ASCII will become entities.
=item serialize_html
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
use warnings;
use vars qw($VERSION);
-$VERSION = "2.0207"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0209"; # VERSION TEMPLATE: DO NOT CHANGE
use constant ERR_OK => 0;
use constant ERR_INTERNAL_ERROR => 1;
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
fallback => 1;
$WARNINGS = 0; # 0: suppress, 1: report via warn, 2: report via die
-$VERSION = "2.0207"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0209"; # VERSION TEMPLATE: DO NOT CHANGE
use constant XML_ERR_NONE => 0;
use constant XML_ERR_WARNING => 1; # A simple warning
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
use warnings;
use vars qw ($VERSION);
-$VERSION = "2.0207"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0209"; # VERSION TEMPLATE: DO NOT CHANGE
use overload
'""' => \&value,
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
order to be consistent with the DOM spec (in older versions attributes and
namespace information was not copied for elements).
+I<<<<<< NOTE >>>>>>cloneNode creates a copy of the selected node that includes the parent's
+defined I<<<<<< namespaces >>>>>> that are in use by the node (or its children) being cloned. That makes it
+useful for extracting a fragment of xml that can be used as a valid xml
+document.
+
=item parentNode
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
use XML::LibXML::Number;
use vars qw($VERSION);
-$VERSION = "2.0207"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0209"; # VERSION TEMPLATE: DO NOT CHANGE
use overload
'""' => \&to_literal,
use warnings;
use vars qw ($VERSION);
-$VERSION = "2.0207"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0209"; # VERSION TEMPLATE: DO NOT CHANGE
use overload
'""' => \&value,
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
use warnings;
use vars qw ($VERSION);
-$VERSION = "2.0207"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0209"; # VERSION TEMPLATE: DO NOT CHANGE
use 5.008_000;
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
use vars qw($VERSION @ISA);
-$VERSION = "2.0207"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0209"; # VERSION TEMPLATE: DO NOT CHANGE
use XML::LibXML;
use XML::SAX::Base;
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
return $XML::LibXML::__threads_shared ? 0 : 1;
}
-$VERSION = "2.0207"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0209"; # VERSION TEMPLATE: DO NOT CHANGE
sub new {
my $class = shift;
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
use XML::LibXML;
use vars qw ($VERSION);
-$VERSION = "2.0207"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0209"; # VERSION TEMPLATE: DO NOT CHANGE
sub CLONE_SKIP {
return $XML::LibXML::__threads_shared ? 0 : 1;
use XML::SAX::Base;
use XML::SAX::DocumentLocator;
-$VERSION = "2.0207"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0209"; # VERSION TEMPLATE: DO NOT CHANGE
@ISA = ('XML::SAX::Base');
sub CLONE_SKIP {
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
use XML::LibXML;
use XML::LibXML::NodeList;
-$VERSION = "2.0207"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0209"; # VERSION TEMPLATE: DO NOT CHANGE
# should LibXML XPath data types be used for simple objects
# when passing parameters to extension functions (default: no)
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
=head1 VERSION
-2.0207
+2.0209
=head1 COPYRIGHT
dTHX;
xs_warn("SV2C: start!\n");
+ SvGETMAGIC(scalar);
if ( scalar != NULL && SvOK(scalar) ) {
STRLEN len = 0;
char * t_pv =SvPV(scalar, len);
EOF
my $evil_xml = <<'EOF';
-<?xml version="1.0"?>
-<!DOCTYPE lolz [
- <!ENTITY lol "lol">
- <!ENTITY lol1 "&lol;&lol;">
- <!ENTITY lol2 "&lol1;&lol1;">
- <!ENTITY lol3 "&lol2;&lol2;">
- <!ENTITY lol4 "&lol3;&lol3;">
- <!ENTITY lol5 "&lol4;&lol4;">
- <!ENTITY lol6 "&lol5;&lol5;">
- <!ENTITY lol7 "&lol6;&lol6;">
- <!ENTITY lol8 "&lol7;&lol7;">
- <!ENTITY lol9 "&lol8;&lol8;">
+<!DOCTYPE root [
+ <!ENTITY ha "Ha !">
+ <!ENTITY ha2 "&ha; &ha;">
+EOF
+
+foreach my $i (2 .. 47)
+{
+ $evil_xml .= sprintf(qq# <!ENTITY ha%d "&ha%d; &ha%d;">\n#, $i+1, $i, $i);
+}
+
+$evil_xml .= <<'EOF';
]>
-<lolz>&lol9;</lolz>
+<root>&ha48;</root>
EOF
-my($parser, $doc);
+my ($parser, $doc, $err);
$parser = XML::LibXML->new;
#$parser->set_option(huge => 0);
$doc = eval { $parser->parse_string($evil_xml); };
+$err = $@;
+
# TEST
-isnt("$@", "", "exception thrown during parse");
+isnt("$err", "", "exception thrown during parse");
# TEST
-like($@, qr/entity.*loop/si, "exception refers to entity reference loop");
+like($err, qr/entity/si, "exception refers to entity maximum loop (libxml2 <= 2.10) or depth (>= 2.11)");
$parser = XML::LibXML->new;
$doc = eval { $parser->parse_string($benign_xml); };
+$err = $@;
+
# TEST
-is("$@", "", "no exception thrown during parse");
+is("$err", "", "no exception thrown during parse");
my $body = $doc->findvalue( '/lolz' );
# TEST
--- /dev/null
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+
+use XML::LibXML;
+
+sub test_one {
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+ my ($ns, $name) = @_;
+ my $doc = XML::LibXML::Document->new;
+ my $foo = $doc->createElement('foo');
+ $foo->appendChild(
+ # we need to access the aliased SV directly, assigning it to a
+ # different variable hides the problem
+ $doc->createElementNS( $$ns, 'bar' ),
+ );
+
+ return is(
+ $foo->toString,
+ qq[<foo><bar xmlns="$$ns"/></foo>],
+ "$name: namespace should be in force",
+ );
+}
+
+my $ns1 = \'urn:a';
+my $ns2 = \substr($$ns1, 0);
+
+# TEST
+test_one $ns1, 'plain scalar';
+# TEST
+test_one $ns2, 'magic scalar';
+# TEST
+test_one \"$$ns2", 'copy of magic scalar';