Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: YKAR [...] cpan.org
Cc:
AdminCc:

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



Subject: HTML::Form::possible_values returns disabled values
Disabled values are returned in 'possible_values' method (the valuses which has <option disabled="disabled"...). Test case attached. I think solution is to filter out disabled items in 'possible_values'. Thank you in advance!
Subject: test.pl
#! /usr/bin/perl use strict; use warnings; use HTML::Form; local $/; my $html = <DATA>; my $form = HTML::Form->parse($html, 'localhost'); my $sel = $form->find_input('test'); $sel->value(($sel->possible_values)[2]); __DATA__ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> </head> <body> <form action="test" method="post"> <select name="test"> <option value="1">One</option> <option value="2">Two</option> <option disabled="disabled" value="3">Three</option> </select> <input type="submit" name="submit" value="Go"> </form> </body> </html>
Show quoted text
> I think solution is to filter out disabled items in 'possible_values'.
Right. I've applied the attached patch now. Will appear in 5.814.
commit 7e1c3ee6d3681b8eddbbb9bef421f5b34315430e Author: Gisle Aas <gisle@aas.no> Date: Wed Jul 23 20:32:24 2008 +0200 HTML::Form::possible_values() should not returned disabled values [RT#35248] diff --git a/lib/HTML/Form.pm b/lib/HTML/Form.pm index 337bbe1..4cc4e84 100644 --- a/lib/HTML/Form.pm +++ b/lib/HTML/Form.pm @@ -1186,13 +1186,13 @@ sub check sub possible_values { my $self = shift; - map $_->{value}, @{$self->{menu}}; + map $_->{value}, grep !$_->{disabled}, @{$self->{menu}}; } sub other_possible_values { my $self = shift; - map $_->{value}, grep !$_->{seen}, @{$self->{menu}}; + map $_->{value}, grep !$_->{seen} && !$_->{disabled}, @{$self->{menu}}; } sub value_names { diff --git a/t/html/form.t b/t/html/form.t index 75a455e..4147dda 100644 --- a/t/html/form.t +++ b/t/html/form.t @@ -3,7 +3,7 @@ use strict; use Test qw(plan ok); -plan tests => 125; +plan tests => 127; use HTML::Form; @@ -565,3 +565,18 @@ $f = HTML::Form->parse(<<EOT, "http://www.example.com"); </form> EOT ok(join(":", $f->find_input("keep_informed")->value_names), "off:"); + +$f = HTML::Form->parse(<<EOT, "http://www.example.com"); +<form action="test" method="post"> +<select name="test"> +<option value="1">One</option> +<option value="2">Two</option> +<option disabled="disabled" value="3">Three</option> +</select> +<input type="submit" name="submit" value="Go"> +</form> +</body> +</html> +EOT +ok(join(":", $f->find_input("test")->possible_values), "1:2"); +ok(join(":", $f->find_input("test")->other_possible_values), "2");