Fix find_all_inputs() and find_all_submits() to handle orphaned inputs in malformed HTML #406
+217
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
find_all_inputs()andfind_all_submits()were not finding all inputs when HTML contained nested forms or premature</form>tags. This is a long-standing issue (Google Code issue #14) where inputs appearing after a premature form closure were invisible to WWW::Mechanize.Example scenario:
Before this fix:
Root Cause
HTML::Form (which WWW::Mechanize uses) stops parsing inputs when it encounters the first
</form>tag. With nested forms or malformed HTML, this tag may belong to an inner/nested form, causing HTML::Form to stop prematurely and miss subsequent inputs.Solution
Enhanced
_extract_forms()to detect and recover orphaned inputs:_attach_orphaned_inputs()method re-scans the HTMLAfter this fix:
Changes
_extract_forms()to call_attach_orphaned_inputs()after HTML::Form parsing_attach_orphaned_inputs()method to detect and attach orphaned inputst/orphaned_inputs.t(14 tests)Testing
Related Issues
Fixes #14 (WM: $mech->find_all_inputs (and $mech->find_all_submits) doesn't)
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
blahblahblah.xx-only-testing.foo/usr/bin/perl t/local/failure.t(dns block)esm.ubuntu.com/usr/lib/apt/methods/https(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Fixes #118
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.