Skip Menu |
 

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

Report information
The Basics
Id: 101549
Status: resolved
Priority: 0/
Queue: XML-Twig

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

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



Subject: Inappropriate croak on syntax errors in parse(*OPENFILEHANDLE) [PATCH]
Date: Wed, 14 Jan 2015 15:32:13 -0800
To: bug-XML-Twig [...] rt.cpan.org
From: Jim Avera <jim.avera [...] gmail.com>
Download (untitled) / with headers
text/plain 1.5k
Hi, The parse() method can be called with either a literal text string or an open file handle. If called with an open fh then syntax errors cause an inappropriate croak with a message saying the wrong method was called (and the syntax error message is not shown). The following code is the culprit: if( !$t && $@=~m{(syntax error at line 1, column 0, byte 0|not well-formed \(invalid token\) at line 1, column 1, byte 1)} && -f $_[0] ) { croak "you seem to have..." } I think the intention is to detect when the user passed a pathname to parse(), in which case parsefile() should have been called. However Perl's -f operator works on pathnames OR open file handles, so the test succeeds when a file handled is passed. This can be fixed by concatenating "" to the argument to -f, so that an open file handle will become a plain string like "*main::FILE" and the test will fail unless there's a strange file named like that. Here's a patch for Twig.pm version 2.23. Thanks for the great software! -Jim Avera --- Twig.pm.ORIG 2015-01-14 14:57:18.703778966 -0800 +++ Twig.pm 2015-01-14 15:24:44.202484250 -0800 @@ -762,7 +762,7 @@ if( !$t && $@=~m{(syntax error at line 1, column 0, byte 0|not well-formed \(invalid token\) at line 1, column 1, byte 1)} - && -f $_[0] + && -f $_[0]."" ) { croak "you seem to have used the parse method on a filename ($_[0]), you probably want parsefile instead"; } return _checked_parse_result( $t, $@);


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.