Skip to content

Commit

Permalink
fix default value bug in val method of Mojo::DOM (closes #926)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 3, 2016
1 parent cd41372 commit 02d7ebf
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes
@@ -1,6 +1,7 @@

6.53 2016-03-03
- Improved Mojo::IOLoop performance slightly.
- Fixed default value bug in val method of Mojo::DOM.

6.52 2016-03-02
- Added is_accepting method to Mojo::IOLoop::Server.
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojo/DOM.pm
Expand Up @@ -166,8 +166,9 @@ sub val {
return $self->{value} // $self->text if (my $tag = $self->tag) eq 'option';

# "input" ("type=checkbox" and "type=radio")
my $type = $self->{type} // '';
return $self->{value} // 'on'
if $tag eq 'input' && grep { $self->{type} // '' eq $_ } qw(checkbox radio);
if $tag eq 'input' && ($type eq 'radio' || $type eq 'checkbox');

# "textarea", "input" or "button"
return $tag eq 'textarea' ? $self->text : $self->{value} if $tag ne 'select';
Expand Down
2 changes: 2 additions & 0 deletions t/mojo/dom.t
Expand Up @@ -2218,6 +2218,7 @@ $dom = Mojo::DOM->new(<<EOF);
<input type="radio" checked name="c" value="C">
<input name="s">
<input type="checkbox" name="t" value="">
<input type=text name="u">
<select multiple name="f">
<option value="F">G</option>
<optgroup>
Expand Down Expand Up @@ -2257,6 +2258,7 @@ is $dom->at('input[name=q]')->val, 'on', 'right value';
is $dom->at('input[name=r]')->val, 'on', 'right value';
is $dom->at('input[name=s]')->val, undef, 'no value';
is $dom->at('input[name=t]')->val, '', 'right value';
is $dom->at('input[name=u]')->val, undef, 'no value';

# PoCo example with whitespace-sensitive text
$dom = Mojo::DOM->new(<<EOF);
Expand Down

0 comments on commit 02d7ebf

Please sign in to comment.