Skip Menu |

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

Report information
The Basics
Id: 127866
Status: new
Priority: 0/
Queue: XML-DOM-Lite

People
Owner: Nobody in particular
Requestors: bauerd007 [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: XML::DOM::Lite::XPath - single/double quote bug - CRITICAL
Date: Fri, 30 Nov 2018 12:24:46 -0500
To: bug-XML-DOM-Lite [...] rt.cpan.org
From: Devon Bauer <bauerd007 [...] gmail.com>
Hello, I’ve found a bug that deals with XPath and how it tries to extract a value from anything within a single or double quote. I will setup a quick example here: Say we have some XML that contains data for a library of books and we want to retrieve certain books by a certain author. Sample XML: <Library> <Books> <Book> <Title>Quickstart Guide To Learning Perl</Title> <Author>Tom Jones</Author> </Book> <Book> <Title>It’s Raining Cats And Dogs</Title> <Author>Lucy Monroe</Author> </Book> <Book> <Title>Perl And CPAN: A Beginners Guide</Title> <Author>Tom Jones</Author> </Book> <Book> <Title>How To Purchase A Car</Title> <Author>Mike Zeal</Author> </Book> </Books> </Library> So we right some XPath to extract books authored by Tom Jones: /Library/Books/Book[contains(Author, 'Tom Jones')] So what XML::DOM::Lite::XPath does, is it notices ‘Tom Jones’ is a single quoted (or double quoted in another case) string and tries to extract the data within the quotes. By doing so it takes ‘Tom Jones’ and passes it to this subroutine: sub makeLiteralExpr { my ($token) = @_; my $value = substr($token->{value}, 1, length($token->{value}) - 1); return new XML::DOM::Lite::XPath::LiteralExpr($value); } It tries to extract Tom Jones from ‘Tom Jones’ by using substr. However, what happens is it extracts Tom Jones’ instead. The thought behind how it extracts the data from a single/double quote is correct but has an error. This line: my $value = substr($token->{value}, 1, length($token->{value}) - 1); Should be this: my $value = substr($token->{value}, 1, length($token->{value}) - 2); It should be minus 2 instead of 1 because… we take $token->{value}… in our case ’Tom Jones’… which has a character length of 11 including space and quotes… offset it by 1 to remove the first quote… so now we have Tom Jones’… which now has a character length of 10 including space and quotes… and are saying we want the substring starting from our offiset of 1 to the length of $token->{value} - 1… which will be 11 - 1 = 10… and this will give us Tom Jones’ instead of the expected Tom Jones. In return all functions that contain single/double quoted strings will not work and makes XPath not very useful. Hope I was straightforward enough in my explanation. Let me know if you have any questions. Thanks