diff --git a/XML-LibXML-2.0202-Parse-an-ampersand-entity-in-SAX-interface.patch b/XML-LibXML-2.0202-Parse-an-ampersand-entity-in-SAX-interface.patch new file mode 100644 index 0000000000000000000000000000000000000000..1f7111917a1052a77638a1f02d2f3de1238911c4 --- /dev/null +++ b/XML-LibXML-2.0202-Parse-an-ampersand-entity-in-SAX-interface.patch @@ -0,0 +1,180 @@ +From 3d0adda7560137309be8b10c63ff41e41dfb1516 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= +Date: Tue, 28 Jan 2020 17:05:32 +0100 +Subject: [PATCH] Parse an ampersand entity in SAX interface +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +After disabling parsing external entities in XML-LibXML-2.0202, +XML::LibXML::SAX interface stopped expanding & and & entities +in attribute values (often found in href XHTML attributes) and +returned "&" instead. This was discovered by a RDF-Trine test +suite failure . + +First, I suspected XML-LibXML +, but it turned out +that the unexpanded entity comes from libxml2 C library itself. And +that it's not just an ommitted expansion, but that it's actually an +escape sequence for "&" characters. Other XML metacharacters (like +"<") are not affeced. Also text nodes are also not affected. My +finding was confirmed by an old libxml2 bug report +. + +This patch "fixes" this discepancy by replacing all "&" +subtstrings with a literal "&" in SAX interface of start_element() +callbacks. + +Signed-off-by: Petr Písař +--- + MANIFEST | 1 + + perl-libxml-sax.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- + t/52_sax_intent.t | 40 ++++++++++++++++++++++++++++++++++++++++ + 3 files changed, 83 insertions(+), 2 deletions(-) + create mode 100755 t/52_sax_intent.t + +diff --git a/MANIFEST b/MANIFEST +index 5248ea5..ccc3410 100644 +--- a/MANIFEST ++++ b/MANIFEST +@@ -174,6 +174,7 @@ t/49callbacks_returning_undef.t + t/49global_extent.t + t/50devel.t + t/51_parse_html_string_rt87089.t ++t/52_sax_intent.t + t/60error_prev_chain.t + t/60struct_error.t + t/61error.t +diff --git a/perl-libxml-sax.c b/perl-libxml-sax.c +index b949d3c..232a879 100644 +--- a/perl-libxml-sax.c ++++ b/perl-libxml-sax.c +@@ -20,6 +20,7 @@ extern "C" { + #include "ppport.h" + + #include ++#include + #include + #include + #include +@@ -639,6 +640,34 @@ PmmGenNsName( const xmlChar * name, const xmlChar * nsURI ) + return retval; + } + ++/* If a value argument does not contain "&", the value pointer is returned. ++ * Otherwise a new xmlChar * string is allocated, the value copied there and ++ * "&" occurences replaced with "&". Then the caller must free it. */ ++static ++xmlChar * ++_expandAmp( const xmlChar *value ) ++{ ++ xmlChar *expanded = NULL; ++ const xmlChar *entity; ++ int length; ++ ++ if (value == NULL || ++ (NULL == (entity = (const xmlChar *)strstr((const char *)value, "&")))) { ++ return (xmlChar *)value; ++ } ++ ++ do { ++ length = entity - value; ++ expanded = xmlStrncat(expanded, value, length); ++ expanded = xmlStrncat(expanded, (const xmlChar *)"&", 1); ++ value += length + 5; /* "&" */ ++ } while (NULL != (entity = (const xmlChar*)strstr((const char *)value, "&"))); ++ ++ expanded = xmlStrcat(expanded, value); ++ ++ return expanded; ++} ++ + HV * + PmmGenAttributeHashSV( pTHX_ PmmSAXVectorPtr sax, + const xmlChar **attr, SV * handler ) +@@ -653,8 +682,8 @@ PmmGenAttributeHashSV( pTHX_ PmmSAXVectorPtr sax, + const xmlChar * nsURI = NULL; + const xmlChar **ta = attr; + const xmlChar * name = NULL; +- const xmlChar * value = NULL; + ++ xmlChar * value = NULL; + xmlChar * keyname = NULL; + xmlChar * localname = NULL; + xmlChar * prefix = NULL; +@@ -665,7 +694,13 @@ PmmGenAttributeHashSV( pTHX_ PmmSAXVectorPtr sax, + while ( *ta != NULL ) { + atV = newHV(); + name = *ta; ta++; +- value = *ta; ta++; ++ /* XXX: libxml2 SAX2 interface does not expand & ++ * entity in the attribute values ++ * ++ * resulting in stray "&" sequences after disabling ++ * external entity expansion ++ * . */ ++ value = _expandAmp(*ta); + + if ( name != NULL && XML_STR_NOT_EMPTY( name ) ) { + localname = xmlSplitQName(NULL, name, &prefix); +@@ -754,6 +789,11 @@ PmmGenAttributeHashSV( pTHX_ PmmSAXVectorPtr sax, + prefix = NULL; + + } ++ ++ if (value != *ta) { ++ xmlFree(value); ++ } ++ ta++; + } + } + +diff --git a/t/52_sax_intent.t b/t/52_sax_intent.t +new file mode 100755 +index 0000000..a45b4d1 +--- /dev/null ++++ b/t/52_sax_intent.t +@@ -0,0 +1,40 @@ ++use strict; ++use warnings; ++use Test::More; ++ ++my %tests = ( ++ # attribte name raw attrib. value expected parsed value ++ predefined => ['"', '"'], # alawys worked ++ numeric => ['A', 'A'], # always worked ++ numericampersand => ['&', '&'], # a regression ++ ampA => ['&A', '&A'], # a corner case ++ Aamp => ['A&', 'A&'], # a corner case ++ AampBampC => ['A&B&C', 'A&B&C'], # a corner case ++); ++plan tests => scalar (keys %tests); ++ ++my $input = '[0]); ++} ++$input .= '/>'; ++ ++diag("Parsing $input"); ++use XML::LibXML::SAX; ++ ++XML::LibXML::SAX->new(Handler => 'Handler')->parse_string($input); ++ ++ ++package Handler; ++sub start_element { ++ my ($self, $node) = @_; ++ for my $attribute (sort keys %{$node->{Attributes}}) { ++ my $name = $node->{Attributes}->{$attribute}->{Name}; ++ Test::More::is( ++ $node->{Attributes}->{$attribute}->{Value}, ++ $tests{$name}->[1], ++ sprintf("%s='%s' attribute", $name, $tests{$name}->[0]) ++ ); ++ } ++} ++ +-- +2.21.1 + diff --git a/XML-LibXML-2.0208-Use-pkgconfig-instead-of-Alien-Libxml2.patch b/XML-LibXML-2.0208-Use-pkgconfig-instead-of-Alien-Libxml2.patch new file mode 100644 index 0000000000000000000000000000000000000000..ce64127768b29febb3b763317e51bfcfdd9df555 --- /dev/null +++ b/XML-LibXML-2.0208-Use-pkgconfig-instead-of-Alien-Libxml2.patch @@ -0,0 +1,57 @@ +diff -up XML-LibXML-2.0208/Makefile.PL.orig XML-LibXML-2.0208/Makefile.PL +--- XML-LibXML-2.0208/Makefile.PL.orig 2022-09-30 09:47:44.807934522 +0200 ++++ XML-LibXML-2.0208/Makefile.PL 2022-09-30 09:49:19.192599793 +0200 +@@ -17,15 +17,31 @@ use warnings; + + require 5.008001; + +-use Alien::Base::Wrapper qw( Alien::Libxml2 ); + use ExtUtils::MakeMaker; + use Config; + + my $SKIP_SAX_INSTALL = $ENV{SKIP_SAX_INSTALL}; + ++my $libs = ''; ++my $inc = ''; ++if (`xml2-config --modules 2>/dev/null`) { ++ $libs = `xml2-config --libs 2>/dev/null`; ++ $inc = `xml2-config --cflags 2>/dev/null`; ++} ++elsif (`pkg-config --modversion libcrypto 2>/dev/null`) { ++ $libs = `pkg-config --libs libxml-2.0 2>/dev/null`; ++ $inc = `pkg-config --cflags libxml-2.0 2>/dev/null`; ++} ++ ++$libs =~ s/[\r\n]+/ /g; ++$inc =~ s/[\r\n]+/ /g; ++ ++die "Could not determine location of libxml2 libs." ++ unless $libs =~ /^-/; ++die "Could not determine location of libxml2 headers." ++ unless $inc =~ /^-/; ++ + my %ConfigReqs = ( +- "Alien::Libxml2" => '0.14', +- "Alien::Base::Wrapper" => 0, + "Config" => 0, + "ExtUtils::MakeMaker" => 0, + ); +@@ -68,15 +84,12 @@ my %prereqs = ( + "warnings" => 0, + ); + +-my %xsbuild_concat = ( ++my %xsbuild = ( + DEFINE => '-DHAVE_UTF8', + OBJECT => '$(O_FILES)', ++ LIBS => $libs, ++ INC => $inc, + ); +-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", diff --git a/perl-XML-LibXML.spec b/perl-XML-LibXML.spec index b41081b58c1e63cec8470d9a659fa8ad5699c5c5..18b4b00c8164f6418f47524135991f54f56d2267 100644 --- a/perl-XML-LibXML.spec +++ b/perl-XML-LibXML.spec @@ -1,12 +1,13 @@ Summary: Perl interface to process XML using the libxml2 library Name: perl-XML-LibXML -Version: 2.0207 -Release: 3%{?dist} +Version: 2.0209 +Release: 1%{?dist} License: (GPL+ or Artistic) and MIT URL: https://metacpan.org/release/XML-LibXML Source0: https://cpan.metacpan.org/authors/id/S/SH/SHLOMIF/XML-LibXML-%{version}.tar.gz +Patch0001: XML-LibXML-2.0202-Parse-an-ampersand-entity-in-SAX-interface.patch # Replace Alien::Libxml2 with pkg-config to reduce dependencies -Patch3000: XML-LibXML-2.0206-Use-pkgconfig-instead-of-Alien-Libxml2.patch +Patch3000: XML-LibXML-2.0208-Use-pkgconfig-instead-of-Alien-Libxml2.patch BuildRequires: gcc make glibc-common coreutils findutils BuildRequires: libxml2-devel pkgconfig(libxml-2.0) @@ -100,6 +101,9 @@ fi %changelog +* Mon Aug 07 2023 rockerzhu - 2.0209-1 +- Upgrade to 2.0209 to fix test with libxml2 2.11. + * Fri Apr 28 2023 OpenCloudOS Release Engineering - 2.0207-3 - Rebuilt for OpenCloudOS Stream 23.05 diff --git a/sources b/sources index 6c35f25a9eadfcb2bcdd49f47b0f9d9355fcc146..cc2ab131d3a94e68dfe8497eaf563ea43b89df2d 100644 --- a/sources +++ b/sources @@ -1 +1 @@ -SHA512 (XML-LibXML-2.0207.tar.gz) = 86bf4200c800e1295161c3217892398dbc65e107ad1a3df8ea7f237350ba67d88ad7b18ab7123e647053a8721bc13a8959ddb101fdc6de18dcaef02c0f0f5b58 +SHA512 (XML-LibXML-2.0209.tar.gz) = 3fd41775477ccb2eb9c72c72453436edcf2ed3db9aa1bbf53451c1407c5b6feeafd3ecc9f30507679f4dba15476044f43b5048da787c20a200831c0669b49262