Skip to content

Commit

Permalink
click_button: fix count of present exclusive options (use a counter)
Browse files Browse the repository at this point in the history
with options "x" and/or "y", @present_exclusive_options would contain "undef" elements, which will be counted too. Therefore click_button with x and y will always have more than > 1 options.
  • Loading branch information
hubandr committed Dec 28, 2023
1 parent 0618985 commit 1c4ecec
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions lib/WWW/Mechanize.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2524,23 +2524,18 @@ sub click_button {
my $self = shift;
my %args = @_;

my $present_exc_options = 0;
for ( keys %args ) {
if ( !/^(number|name|value|id|input|x|y)$/ ) {
$self->warn(qq{Unknown click_button parameter "$_"});
}
else {
$present_exc_options++ if !/^(?:x|y)$/;
}
}

my %exclusive_options = (
id => 1,
input => 1,
name => 1,
number => 1,
value => 1,
);

my @present_exclusive_options = @exclusive_options{ keys %args };

if ( scalar @present_exclusive_options > 1 ) {
# die if more than one exclusive option is provided
if ( $present_exc_options > 1 ) {
$self->die(
'click_button: More than one button selector has been used');
}
Expand Down

0 comments on commit 1c4ecec

Please sign in to comment.