This is spawned from looking into
problem loggin into pm .. It appears that the problem there was that a field value was too long -- the browser respects the http attribute
maxlength=8, 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.
So i started poking at
WWW::Mechanize and
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:
(A) In HTML::Form::TextInput::value() (it's defined in
HTML/Form.pm),
change
$self->{value} = shift; to:
my $v = shift;
my $n = exists $self->{maxlength} ? $self->{maxlength} : undef;
$self->{value} = $n ? substr($v,0,$n) : $v;
(B) In
WWW/Mechanize.pm,
add logic in the
field() and
set_fields() methods to do the same thing, where
$n = $form->find_input(...)->{maxlength}. Would have to do something to the
$form->value($name => $value); calls, too.
While (B) limits it to this specific case, it's a much messier implementation, and breaks encapsulation.
Thoughts/comments?
(A) vs (B)?
Or (C) of neither, and user constructing the post should know the limits/restrictions?
Also, should (probably yes?) either solution be conditional on some option/config setting so as to leave default behavior alone?