Skip Menu |

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

Report information
The Basics
Id: 2284
Status: resolved
Worked: 30 min
Priority: 0/
Queue: XML-Twig

People
Owner: MIROD [...] cpan.org
Requestors: eric [...] timebytes.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 3.09
Fixed in: 3.10



Subject: Possible bug in regexp functionality
Perl v5.6.1 running on Mandrake Linux 8.2 using kernel 2.2.19 XML::Twig 3.09 Code: if ($keyword) { @elementList = $list->get_xpath($itemField . '[string()=~/' . $ke yword . '/]'); } else { @elementList = $list->children($itemField); } Works fine, returning elements with text matching $keyword. However, adding the /i modifier breaks the code: if ($keyword) { @elementList = $list->get_xpath($itemField . '[string()=~/' . $ke yword . '/i]'); } error in xpath expression item[string()=~/falling/i] at i at GetAllDefs.cgi line 62 adding white space causes the code to compile and run, but silently fail to return results, which is incorrect for my dataset: if ($keyword) { @elementList = $list->get_xpath($itemField . '[string() = ~/' . $ke yword . '/i]'); } Adding white space to the original expression: if ($keyword) { @elementList = $list->get_xpath($itemField . '[string()=~/' . $ke yword . ']'); } also causes the code to silently fail to produce results. Any input is welcome! Eric Safern eric@timebytes.com http://www.timebytes.com PS. I've pasted the entire code below: #!/usr/bin/perl -wI/home/mystic/lib/perl5/site_perl use strict; use HTML::Template; use CGI; use POSIX; use CGI::Carp qw(fatalsToBrowser); use XML::Twig; my @loopData = (); my $q = new CGI; my $topic = ($q->param('topic') or 'crystals'); my $keyword = ($q->param('keyword') or ''); $topic =~tr/A-Z/a-z/; $keyword =~tr/A-Z/a-z/; my $containerField = "list"; my $itemField = "item"; my $typeField = "type"; my $textField = "text"; # open the html template my $template = HTML::Template->new(filename => '/home/mystic/www/template s/all_defs.tmpl'); my $file = "/home/mystic/data/dict.xml"; my $twig = new XML::Twig(TwigHandlers => { 'list[@type="' . $topic . '"]' => \&doList}); # print the header print "Content-type: text/html \n\n"; $twig->parsefile($file); $topic =~tr/a-z/A-Z/; # Go back to all caps for the template $template->param(TOPIC => $topic); $template->param(KEYWORD => $keyword); $template->param(RESULTS => \@loopData); # print the template print $template->output(); exit 0; sub doList { my ($t, $list) = @_; my @elementList; if ($keyword) { @elementList = $list->get_xpath($itemField . '[string()=~/' . $ke yword . '/]'); } else { @elementList = $list->children($itemField); } foreach my $element (@elementList) { my %rowData; $rowData{ITEM} = $element->att('id'); push (@loopData, \%rowData); } return; } And here's an xml data sample: <?xml version="1.0" encoding="US-ASCII" standalone="no"?> <!DOCTYPE fortunes SYSTEM "http://linux.timebytes.com/dtds/fortunes.dtd"> <dict xml:lang="en-US">> <list type="dreams"> <item id="falling" src="mystictones"> <text>Fear of Falling - life is out of control.</text> </item> <item id="leaves" src="mystictones"> <text>Green -- health and happiness; falling -- a parting of ways w ith someone.</text> </item> </list> </dict>
Yes, this is a bug, it will fixed in 3.10 (snapshot available at http://www.xmltwig.com/xmltwig/) __ Mirod