Checkboxes with same name will not be grouped if some other inputs exists between them
- Dominant language
- Python
- Stars
- 3.7k
- Forks
- 336
- PR merge metrics
- No merged PRs in 30d
Description
I found that checkboxes with same name will not be grouped if some other inputs exists between them.
``` python
from robobrowser.forms.form import _parse_fields
html = '''
vocals
guitar
drums
bass
'''
_fields = _parse_fields(BeautifulSoup(html))
for cbx in _fields:
print(cbx.name, cbx.options)
```
which output
```
member ['mercury', 'may']
member ['taylor', 'deacon']
```
As seen, 2 robobrowser.forms.fields.Checkbox instances were created, with the same name, options different. I thought it would be _one_ instance, with 4 options.
Maybe it's a bug? I have no idea.
[relevant code](https://github.com/jmcarp/robobrowser/blob/master/robobrowser/forms/form.py#L34)
``` python
def _group_flat_tags(tag, tags):
"""Extract tags sharing the same name as the provided tag. Used to collect
options for radio and checkbox inputs.
:param Tag tag: BeautifulSoup tag
:param list tags: List of tags
:return: List of matching tags
"""
grouped = [tag]
name = tag.get('name', '').lower()
while tags and tags[0].get('name', '').lower() == name: # <---- HERE
grouped.append(tags.pop(0))
return grouped
```
Contributor guide
Research direction
Start in robobrowser/forms/form.py, especially _parse_fields and _group_flat_tags, and run the provided BeautifulSoup reproduction. Trace how intervening inputs affect grouping of same-name checkboxes. Done means the example produces one Checkbox instance named member with all four options, with regression coverage for the intervening input case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100