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?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.