Skip Menu |

This queue is for tickets about the XML-SAX CPAN distribution.

Report information
The Basics
Id: 19173
Status: resolved
Priority: 0/
Queue: XML-SAX

People
Owner: Nobody in particular
Requestors: tom.schindl [...] bestsolution.at
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in:
  • 0.14
  • 0.15
Fixed in: (no value)



Subject: Processing Instruction not working $data->{Target} and $data->{Data} wrong
Well when trying to fetch processing instructions: $data->{Target} holds the e.g. 'type="test/xsl" herf="my.xsl"' instead of "xml-stylesheet" $data->{Data} is empty!
Subject: bug.t
use Test; BEGIN { plan tests => 2 } use XML::SAX::PurePerl; use XML::SAX::PurePerl::DebugHandler; use XML::SAX::ParserFactory; my $value; { local $/ = undef; open(IN,"<testfiles/03c.xml"); $value = <IN>; close(IN); } my $parser = XML::SAX::ParserFactory->parser(Handler => new My::SAXFilter()); $parser->parse_string($value); package My::SAXFilter; use base qw(XML::SAX::Base); sub processing_instruction { my $this = shift; my $data = shift; main::ok($data->{Target},"xml-stylesheet"); main::ok($data->{Data},"type=\"text/xsl\" href=\"processorinxml/base.xsl\""); }
Subject: patch.txt
--- SAX/PurePerl.pm 2006-04-24 01:20:09.000000000 +0200 +++ SAX/PurePerl.pm.tom 2006-05-09 23:55:42.000000000 +0200 @@ -624,28 +624,31 @@ my ($target, $data); $target = $self->Name($reader) || $self->parser_error("PI has no target", $reader); + if ($self->skip_whitespace($reader)) { - $target = ''; + my $tdata = ''; while (1) { my $data = $reader->data; $self->parser_error("End of data seen while looking for close PI marker", $reader) unless length($data); if ($data =~ /^(.*?)\?>/s) { - $target .= $1; + $tdata .= $1; $reader->move_along(length($1) + 2); last; } else { - $target .= $data; + $tdata .= $data; $reader->move_along(length($data)); } } + $data = $tdata; } else { my $data = $reader->data(2); $data =~ /^\?>/ or $self->parser_error("PI closing sequence not found", $reader); $reader->move_along(2); } + $self->processing_instruction({ Target => $target, Data => $data }); return 1;
From: ntyni [...] iki.fi
On Tue May 09 17:58:01 2006, guest wrote: Show quoted text
> Well when trying to fetch processing instructions: > $data->{Target} holds the e.g. 'type="test/xsl" herf="my.xsl"' instead > of "xml-stylesheet" > $data->{Data} is empty!
Hi, this is still present in 0.15, and it's breaking at least XML::Filter::Sort (see http://bugs.debian.org/419689). Cheers, -- Niko Tyni ntyni@iki.fi
From: leonerd-cpan [...] leonerd.org.uk
On Tue May 09 17:58:01 2006, guest wrote: Show quoted text
> Well when trying to fetch processing instructions: > $data->{Target} holds the e.g. 'type="test/xsl" herf="my.xsl"' instead > of "xml-stylesheet" > $data->{Data} is empty!
I too have noticed this same error; it's causing test failures of my own module: http://www.nntp.perl.org/group/perl.cpan.testers/2007/06/msg513054.html I've come up with a similar patch to this, along with a test script. Is anyone currently maintaining this module, and could apply either the patch already supplied, or this one I have made? This is a fairly major bug to have had open for 2 months now... -- Paul Evans
diff -urN XML-SAX-0.15/SAX/PurePerl.pm XML-SAX-0.15-fixedPI/SAX/PurePerl.pm --- XML-SAX-0.15/SAX/PurePerl.pm 2007-02-08 05:24:40.000000000 +0000 +++ XML-SAX-0.15-fixedPI/SAX/PurePerl.pm 2007-06-26 00:33:15.000000000 +0100 @@ -622,22 +622,21 @@ if ($data =~ /^<\?/) { $reader->move_along(2); - my ($target, $data); - $target = $self->Name($reader) || + my $target = $self->Name($reader) || $self->parser_error("PI has no target", $reader); + my $pi_data = ''; if ($self->skip_whitespace($reader)) { - $target = ''; while (1) { my $data = $reader->data; $self->parser_error("End of data seen while looking for close PI marker", $reader) unless length($data); if ($data =~ /^(.*?)\?>/s) { - $target .= $1; + $pi_data .= $1; $reader->move_along(length($1) + 2); last; } else { - $target .= $data; + $pi_data .= $data; $reader->move_along(length($data)); } } @@ -647,7 +646,7 @@ $data =~ /^\?>/ or $self->parser_error("PI closing sequence not found", $reader); $reader->move_along(2); } - $self->processing_instruction({ Target => $target, Data => $data }); + $self->processing_instruction({ Target => $target, Data => $pi_data }); return 1; } diff -urN XML-SAX-0.15/t/17pi.t XML-SAX-0.15-fixedPI/t/17pi.t --- XML-SAX-0.15/t/17pi.t 1970-01-01 01:00:00.000000000 +0100 +++ XML-SAX-0.15-fixedPI/t/17pi.t 2007-06-26 00:32:36.000000000 +0100 @@ -0,0 +1,43 @@ +use Test; +BEGIN { plan tests => 6 } +use XML::SAX::PurePerl; +use XML::SAX::PurePerl::DebugHandler; + +my $handler = TestPIHandler->new(); +ok($handler); + +my $parser = XML::SAX::PurePerl->new(Handler => $handler); +ok($parser); + +$handler->{test_pi} = [ + { Target => "foo", Data => "foo" }, + { Target => "foo", Data => "" }, +]; +$parser->parse_uri("testfiles/03a.xml"); + +## HELPER PACKAGE ## + +package TestPIHandler; + +use Test; + +sub new { + my $class = shift; + my %opts = @_; + bless \%opts, $class; +} + +sub reset { + my $self = shift; + %$self = (); +} + +sub processing_instruction { + my ($self, $el) = @_; + if (my $pi = shift @{ $self->{test_pi} }) { + foreach my $key (keys %$pi) { + #warn $key, "\n"; + ok("$key: $el->{$key}", "$key: $pi->{$key}"); + } + } +}
Patch applied. Thanks. Sorry for delay.