diff --git a/form2request/_base.py b/form2request/_base.py index ceeb8f7..ed685b2 100644 --- a/form2request/_base.py +++ b/form2request/_base.py @@ -149,7 +149,15 @@ def _data( ) values: list[FormdataKVType] = [ (k, "" if v is None else v) - for k, v in ((e.name, e.value) for e in inputs) + for k, v in ( + ( + # Unset name for selects without options. + (None, None) + if e.tag == "select" and not e.value_options + else (e.name, e.value) + ) + for e in inputs + ) if k and k not in keys ] items = data.items() if isinstance(data, dict) else data diff --git a/tests/test_main.py b/tests/test_main.py index 82c9788..3e6797d 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -590,6 +590,30 @@ b"", ), ), + # Single-choice select with no options. + ( + "https://example.com", + b"""
""", + {}, + Request( + "https://example.com", + "GET", + [], + b"", + ), + ), + # Single-choice select with no options but with a value. + ( + "https://example.com", + b"""
""", + {}, + Request( + "https://example.com", + "GET", + [], + b"", + ), + ), # Single-choice select with multiple options. The first one is # selected. ( @@ -659,6 +683,30 @@ b"", ), ), + # Multiple-choice select without options. + ( + "https://example.com", + b"""
""", + {}, + Request( + "https://example.com", + "GET", + [], + b"", + ), + ), + # Multiple-choice select without options but with a value. + ( + "https://example.com", + b"""
""", + {}, + Request( + "https://example.com", + "GET", + [], + b"", + ), + ), # Values are URL-encoded, with plus signs instead of spaces. ( "https://example.com",