perlmeditation
davidrw
This is spawned from looking into [id://661065] .. It appears that the problem there was that a field value was too long -- the browser respects the http attribute <c>maxlength=8</c>, and so truncates the value before posting. But when trying to submit the form directly w/WWW::Mechanize, it doesn't know to truncate, and sends the full string, and authentication must fail because server compares against the 8-character password.<br>
<br>
So i started poking at [mod://WWW::Mechanize] and [mod://HTML::Form] to see where logic could be added to truncate values if the input field has a maxlength, and came up w/two potential spots:<br>
<br>
(A) In HTML::Form::TextInput::value() (it's defined in
[http://search.cpan.org/src/GAAS/libwww-perl-5.808/lib/HTML/Form.pm|HTML/Form.pm]),
change <c>$self->{value} = shift;</c> to:
<code>
my $v = shift;
my $n = exists $self->{maxlength} ? $self->{maxlength} : undef;
$self->{value} = $n ? substr($v,0,$n) : $v;
</code>
<br>
(B) In
[http://search.cpan.org/src/PETDANCE/WWW-Mechanize-1.34/lib/WWW/Mechanize.pm|WWW/Mechanize.pm],
add logic in the <c>field()</c> and <c>set_fields()</c> methods to do the same thing, where <c>$n = $form->find_input(...)->{maxlength}</c>. Would have to do something to the <c>$form->value($name => $value);</c> calls, too.<br>
<br>
While (B) limits it to this specific case, it's a much messier implementation, and breaks encapsulation.<br>
<br>
Thoughts/comments?<br>
(A) vs (B)?<br>
Or (C) of neither, and user constructing the post should know the limits/restrictions?<br>
Also, should (probably yes?) either solution be conditional on some option/config setting so as to leave default behavior alone?