Skip Menu |

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

Report information
The Basics
Id: 76696
Status: open
Priority: 0/
Queue: XML-LibXML

People
Owner: Nobody in particular
Requestors: SREZIC [...] cpan.org
Cc: srezic [...] iconmobile.com
AdminCc:

Bug Information
Severity: (no value)
Broken in:
  • 1.70
  • 1.96
Fixed in: (no value)



Subject: keep_blanks has no effect on parse_balanced_chunk anymore
Specifying ->keep_blanks(0) has no effect on parse_balanced_chunk anymore. The script below used to pass with XML::LibXML 1.69, but is broken since 1.70 and also with the newest 1.96. Regards, Slaven #!/usr/bin/perl use strict; use warnings; use Test::More 'no_plan'; use XML::LibXML; my $xml = <<EOF; <bla> <foo/> </bla> EOF my $p = XML::LibXML->new; $p->keep_blanks(0); is $p->parse_balanced_chunk($xml)->serialize, "<bla><foo/></bla>\n"; __END__
Hi Slaven, thanks for the repot and the test. I'll look into it. Regards, -- Shlomi Fish On Thu Apr 19 06:01:51 2012, SREZIC wrote: Show quoted text
> Specifying ->keep_blanks(0) has no effect on parse_balanced_chunk > anymore. The script below used to pass with XML::LibXML 1.69, but is > broken since 1.70 and also with the newest 1.96. > > Regards, > Slaven > > #!/usr/bin/perl > use strict; > use warnings; > > use Test::More 'no_plan'; > use XML::LibXML; > > my $xml = <<EOF; > <bla> > <foo/> > </bla> > EOF > > my $p = XML::LibXML->new; > $p->keep_blanks(0); > is $p->parse_balanced_chunk($xml)->serialize, "<bla><foo/></bla>\n"; > > __END__
I assume the problem was caused by changing the keep_blanks/no_blanks support from using xmlKeepBlanksDefault() to the use of the parser option XML_PARSER_NOBLANKS. Maybe the code behind parse_balanced_chunk() cannot deal with the parser options, but still needs xmlKeepBlanksDefault(). The attached patch works for me, but I don't know if this is the correct way to fix this problem. Regards, Slaven
Subject: parse-balanced-chunk.patch
diff --git a/LibXML.xs b/LibXML.xs index 535302c..35e1ab1 100644 --- a/LibXML.xs +++ b/LibXML.xs @@ -891,6 +891,12 @@ LibXML_init_parser( SV * self, xmlParserCtxtPtr ctxt ) { } if (ctxt) xmlCtxtUseOptions(ctxt, parserOptions ); /* Note: sets ctxt->linenumbers = 1 */ + if (parserOptions & XML_PARSE_NOBLANKS) { + xmlKeepBlanksDefault(0); + } else { + xmlKeepBlanksDefault(1); + } + item = hv_fetch( real_obj, "XML_LIBXML_LINENUMBERS", 22, 0 ); if ( item != NULL && SvTRUE(*item) ) { if (ctxt) ctxt->linenumbers = 1;
Hi Slaven, thanks for the report, the test case and the fix. It was applied (with some comments, cleanups and clarifications) in the repository and released to CPAN as release "1.97". Please open a new ticket if there are more problems, as I'm resolving this ticket. Regards, -- Shlomi Fish
Unfortunately, there is no way to pass parser options to xmlParseBalancedChunkMemory. So if you want to use that function without keeping blanks, you have to change the global setting. But using globals to configure a library is a really bad idea, since there might be several other users of libxml2 in the same process (think of an Apache process with mod_perl, PHP and all kind of other modules). If you set the keep_blanks global, all other users of library will be affected and it's possible that something breaks in a very hard to debug way. That was the motivation behind removing the calls to xmlKeepBlanksDefault in version 1.70.