Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass strict/verbose constructor args to HTML::Form #256

Merged
merged 5 commits into from
Oct 18, 2018

Conversation

simbabque
Copy link
Contributor

Closes #255

@oalders
Copy link
Member

oalders commented Oct 11, 2018

Thanks so much for this. Should we add a test that demonstrates that strict_forms can be disabled on a case by case basis when calling submit_form?

@oalders
Copy link
Member

oalders commented Oct 11, 2018

Also, it would be great to document this new behaviour in the best practices section as well as the SYNOPSIS.

@simbabque
Copy link
Contributor Author

simbabque commented Oct 11, 2018 via email

@oalders
Copy link
Member

oalders commented Oct 11, 2018

I was looking specifically for strict_forms => 0 in a submit_form call in the test, but I don't see it.

@simbabque
Copy link
Contributor Author

simbabque commented Oct 11, 2018 via email

@oalders
Copy link
Member

oalders commented Oct 11, 2018

Thanks! Enjoy your meeting. :)

@simbabque
Copy link
Contributor Author

Should we add a test that demonstrates that strict_forms can be disabled on a case by case basis when calling submit_form?

I've updated my commit to fix the test.

Also, it would be great to document this new behaviour in the best practices section as well as the SYNOPSIS.

I've done the best practices, but I am not sure about the SYNOPSIS.

From the amount of questions I've answered about Mech on Stack Overflow I believe a lot of new users start by copying the SYNOPSIS code without really understanding what's going on there. For them, the strict forms option would not really make their code more robust, but just confuse them more because they will likely be confronted with even more errors they don't understand.

On the other hand, it helps to keep these new users on track. I've added it as a separate commit so we can cherry-pick it out if needed.

I do not think we should be talking about verbose mode a lot. Catching these warnings is quite an advanced topic. Having it documented as an option is probably enough for people who know what they are doing.

@petdance
Copy link
Contributor

I think it would be good if the docs explained what the strict/verbose flags do when passed through to HTML::Form. It doesn't need to replicate the docs, but a one-sentence summary would be helpful to the reader.

And is verbose not a best practice?

@simbabque
Copy link
Contributor Author

simbabque commented Oct 15, 2018

I think it would be good if the docs explained what the strict/verbose flags do when passed through to HTML::Form. It doesn't need to replicate the docs, but a one-sentence summary would be helpful to the reader.

I included that. Please see https://github.com/libwww-perl/WWW-Mechanize/pull/256/files#diff-9b033b946ad0ade000c98612745f570eR248.

And is verbose not a best practice?

I guess it should be, but it's not the default in HTML::Form and I believe we should not just turn on a new feature that will introduce fatal errors where none were there before. That would break a lot of users' code.

@petdance
Copy link
Contributor

I included that.

Sorry, my mistake. That looks good.

As to verbose being a best practice, I didn't think that listing it in "best practices" would include making it be the default. We'd just be specifying that it's a good idea, right?

Note that I haven't used either of these features myself, but will be eager to play with them when they go live.

@simbabque
Copy link
Contributor Author

As to verbose being a best practice, I didn't think that listing it in "best practices" would include making it be the default. We'd just be specifying that it's a good idea, right?

Oh, I misunderstood. Sorry about that. However, was already in the best practices section. I've extended it in my commit. Please see https://github.com/libwww-perl/WWW-Mechanize/pull/256/files#diff-9b033b946ad0ade000c98612745f570eR3219.

@petdance
Copy link
Contributor

Is there anything you'd like me to do to test this out?

@simbabque
Copy link
Contributor Author

If you're asking me, feel free to play with it. I wrote unit tests, but I didn't actually use it. I don't use Mech a lot lately as my focus at $work has shifted. At the moment I'm doing these tickets for fun and for the sake of doing them. :)

Copy link

@PatrickCronin PatrickCronin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Olaf was looking for volunteers to review this PR. I suspect he's trying to draw more attention to this dist. Very clever Olaf! Anyway, here's my two cents.

=item * C<< strict_forms => [0|1] >>

Globally sets the HTML::Form strict flag which causes form submission to
croak if any of the passed fields don't exist on the page, and/or a value

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"any of the passed fields don't exist on the page" seems slightly inaccurate. Perhaps something like "all passed fields can't be found in a single form on the page"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think neither is fully correct. This is not about searching for forms as far as I understand. It's for once it's found a form, that form will be strict, so it will not silently ignore if you try to pass in extra fields. It doesn't matter how it found that form. If you use a method that will find a form based on fields, then it simply won't find it if you ask for superfluous (or maybe misspelled) fields. That behaviour hasn't changed, it was already there.

I believe saying any of the passed fields don't exist on the form makes more sense.


This behavior can also be turned on globally by passing C<< strict_forms => 1>> to
C<<WWW::Mechanize->new>>. If you do that, you can still disable it for individual calls
by passing C<< strict_forms => 0>> here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

password => 'lost-and-alone',
extra_field => 123, # field does not exist
}
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good docs.

);
isa_ok( $form, 'HTML::Form' );
is($form->attr('name'), '4th_form_1', 'fourth form matches');
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test seems very similar to the one two blocks above. Does it test different functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied all of those from the existing form_with_fields.t, because I wanted to make sure all the tests we already have also pass when strict is on. I did not actually prove those tests to be correct in this PR. I think the idea for these two is that in the 1st_form test, it tests the outcome of calling form_with_fields() with one argument, while the 4th_form_1 test calls it with two arguments. I'd like to keep those in for consistency.

isa_ok( $forms[0], 'HTML::Form' );
isa_ok( $forms[1], 'HTML::Form' );
is($forms[0]->attr('name'), '3rd_form_ambiguous', 'first result of 3rd_form_ambiguous');
is($forms[0]->attr('name'), '3rd_form_ambiguous', 'second result of 3rd_form_ambiguous');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how this is different from the previous line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot. See above please. This seems to have been broken in form_with_fields.t already, but I missed it. I will fix it in both tests.

@petdance
Copy link
Contributor

I'd like to suggest/request that when all this is churned over that a new PR gets made with all the changes and feedback. It's difficult to look over multiple commits on something like this.

@simbabque
Copy link
Contributor Author

I'd like to suggest/request that when all this is churned over that a new PR gets made with all the changes and feedback. It's difficult to look over multiple commits on something like this.

I agree. When everyone's happy, I'll squash down the branch and create a single-commit new PR.

@petdance
Copy link
Contributor

One other request: I'd like it if we used proper capitalization and punctuation in comments, so that instead of:

# enable strict form processing to catch typos and non-existant form fields

we have

# Enable strict form processing to catch typos and non-existent form fields.

Makes it easier to read. (Also, it's "non-existent" not "non-existant".)

@petdance
Copy link
Contributor

Is there a timeframe for making a release of WWW::Mechanize with this PR in it? I'm going to put out a release of Test::WWW::Mechanize soon, and I'd like to mention in it that the underlying WWW::Mechanize has new features in it that may be useful to testers.

@oalders
Copy link
Member

oalders commented Oct 17, 2018

I can release this on the same day as this gets merged. I'm happy with the current state of things. The code comments could be cleaned up here or in a different merge. I'm not picky about that.

@petdance
Copy link
Contributor

I just ran a small subset of our test suite using this Mech branch and the new options enabled and already turned up a couple of problems.

strict_forms caused an error of "Input 'sb_selectedoption' is readonly at /home/alester/...."

verbose_forms threw a warning saying " outside

", which combined with Test::Warnings, made my test fail (good!).

👍 to this level of pickiness. I'll start testing in earnest once it hits the CPAN.

@simbabque
Copy link
Contributor Author

I'd like it if we used proper capitalization and punctuation in comments

I don't want to nitpick, but it seems that actually most of the code base has single sentence comments that start with a capital letter, but do not have a full stop. There are only full stops if the comment has more than one sentence. However, this is in the synopsis. So it's not even a real comment.

I am all for consistency, so I'll change that.

@oalders, do you want me to merge them down and create a new PR or are we OK with a bit of history going in?

@oalders
Copy link
Member

oalders commented Oct 18, 2018

@simbabque in the interest of getting this done, I'm going to merge what we have here and get a release out there. I think it looks good.

@oalders oalders merged commit 51872f0 into libwww-perl:master Oct 18, 2018
@oalders
Copy link
Member

oalders commented Oct 18, 2018

Thanks @simbabque, @petdance and @PatrickCronin!

@oalders
Copy link
Member

oalders commented Oct 18, 2018

New version is now on CPAN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants