Skip Menu |

This queue is for tickets about the libwww-perl CPAN distribution.

Report information
The Basics
Id: 8327
Status: resolved
Priority: 0/
Queue: libwww-perl

People
Owner: Nobody in particular
Requestors: peter.stevens [...] ch-open.ch
Cc:
AdminCc:

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



Subject: mech->select(value) with invalid value causes a croak in HTML::Form
Background Info: Linux webfileserver 2.4.18-4SGI_XFS_1.1_umask #1 Fri Nov 15 20:09:54 CET 2002 i686 unknown This is perl, v5.8.5 built for i686-linux # $Id: Form.pm,v 1.44 2004/06/16 10:06:07 gisle Exp $ $Header: /cvsroot/www-mechanize/www-mechanize/lib/WWW/Mechanize.pm, v 1.129 2004/04/10 05:30:10 petdance Exp $ Attempting to mech->select with an invalid value causes HTML::Form to croak (line 440). mech->select does not check for this case before calling form->value.
#!/usr/local/bin/perl use strict; use CLASS; use WWW::Mechanize; my $mech = WWW::Mechanize->new( autocheck => 0 ); $mech->get( $homepage ); # ... $mech->select("mtn", $PhoneNumber ); # mtn is a valid select field in the first form, # however $PhoneNumber is not a valid option in that form # not reached if (!$mech->success) { printf "$CLASS: Could not select $PhoneNumber: " . $mech->response->status_line . "\n" ; } ################ # Debugger output: # Illegal value '2125551212' for field 'mtn' at /usr/local/lib/perl5/site_perl/5.8.5/WWW/Mechanize.pm line 740 # at /usr/local/lib/perl5/site_perl/5.8.5/HTML/Form.pm line 404 # HTML::Form::value('HTML::Form=HASH(0x8d97bd0)', 'mtn', 4107101652) # called at /usr/local/lib/perl5/site_perl/5.8.5/WWW/Mechanize.pm line 740 # WWW::Mechanize::select('WWW::Mechanize=HASH(0x8aa5150)', 'mtn', 4107101652) # called at /export/home/mmtest/lib/Verizon.pm line 98
Show quoted text
> Attempting to mech->select with an invalid value causes HTML::Form to > croak (line 440). mech->select does not check for this case before > calling form->value.
What would you suggest instead?
From: Peter Stevens
[PETDANCE - Tue Nov 9 10:03:42 2004]: Show quoted text
> > What would you suggest instead? >
I'm not too particular: Either need a way to trap it in advance, use the return code of select, or check the status afterwards. Given my choice, I'd prefer the second alternative, especially since select does not appear to return anything useful. As it is, I am rather stuck. I can't check it without parsing the HTML myself nor can I prevent the users from entering wrong information. All I can do is note when a cron job fails with a perl stack dump. Or is there a way to trap the error? In any case, it seems that a low level utility like HTML::Form should not be croaking on an input error. Thanks, Peter
Moving to HTML-Form queue for further discussion/resolution. Mark
RT-Send-CC: rjbs [...] cpan.org
One solution to this is to use HTML::Form::ForceValue: http://search.cpan.org/dist/HTML-Form-ForceValue/ However the feature that this distribution is small enough, it would be nice if it existed as part of HTML::Form instead. Mark
From: bitcard [...] foster.nce.ubc.ca
I encountered this bug today, although I was using form->param and later form->value. Two things: 1) The error message is different: form->param: Illegal value 'Dimethyl (K)' for field 'IT_MODS' at c:/Perl/lib/HTML/Form.pm line 512 form->value: Illegal value 'Dimethyl (K)' for field 'IT_MODS' at c:\dtasc_wrapper\mascot.pl line 240 2) The error message could say something about how it's an error to select a value that isn't an option in a list. I initially thought that the illegal value was a problem with spaces or maybe brackets, and that url-encoding would be necessary. It turns out the original web page added options using javascript, which is why HTML::Form would not allow me to select them. HTML::Form::ForceValue looks like an easy solution. The hard solution would have been to dynamically rewrite the page and then get www::mechanize to re-parse everything. Thanks!
HTML::Form has been non-strict (by default) about input values since LWP-5.817.