Skip to content

gh-154317: Add test for parse_qsl/parse_qs strict_parsing on malformed fields#154207

Open
nikolauspschuetz wants to merge 1 commit into
python:mainfrom
nikolauspschuetz:test-parse-qsl-strict-parsing
Open

gh-154317: Add test for parse_qsl/parse_qs strict_parsing on malformed fields#154207
nikolauspschuetz wants to merge 1 commit into
python:mainfrom
nikolauspschuetz:test-parse-qsl-strict-parsing

Conversation

@nikolauspschuetz

@nikolauspschuetz nikolauspschuetz commented Jul 19, 2026

Copy link
Copy Markdown

Add test coverage for the strict_parsing=True branch of urllib.parse.parse_qsl and parse_qs.

The existing strict_parsing tests only pass empty inputs ("", b""), which return early before the parsing loop, so the ValueError branch for a malformed field — one without = — was never exercised. This adds a test that:

  • a field without = raises ValueError under strict_parsing for both str ('a=1&b&c=3') and bytes (b'a=1&b') inputs, and
  • well-formed input still parses correctly under strict_parsing.

Test-only change; no behavior change. The asserted behavior is identical across CPython 3.9–3.14.

@bedevere-app bedevere-app Bot added the tests Tests in the Lib/test dir label Jul 19, 2026
@python-cla-bot

python-cla-bot Bot commented Jul 19, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app

bedevere-app Bot commented Jul 19, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@nikolauspschuetz
nikolauspschuetz force-pushed the test-parse-qsl-strict-parsing branch 2 times, most recently from 5bd2489 to 8995d88 Compare July 20, 2026 00:14
@nikolauspschuetz

Copy link
Copy Markdown
Author

This is a test-only change (adds coverage under Lib/test/, no behavior change), so it should be eligible for the skip news label.

@nikolauspschuetz nikolauspschuetz changed the title Add test for parse_qsl/parse_qs strict_parsing on malformed fields gh-154317: Add test for parse_qsl/parse_qs strict_parsing on malformed fields Jul 20, 2026
@nikolauspschuetz
nikolauspschuetz force-pushed the test-parse-qsl-strict-parsing branch from 8995d88 to bf15955 Compare July 20, 2026 23:11
@bedevere-app

bedevere-app Bot commented Jul 20, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@nikolauspschuetz
nikolauspschuetz force-pushed the test-parse-qsl-strict-parsing branch from bf15955 to 476fae1 Compare July 20, 2026 23:18
@bedevere-app

bedevere-app Bot commented Jul 20, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@nikolauspschuetz
nikolauspschuetz marked this pull request as ready for review July 20, 2026 23:18
@nikolauspschuetz
nikolauspschuetz force-pushed the test-parse-qsl-strict-parsing branch from 476fae1 to ce9972e Compare July 20, 2026 23:28
@bedevere-app

bedevere-app Bot commented Jul 20, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

…lformed fields

The strict_parsing=True path in urllib.parse.parse_qsl and parse_qs was only
exercised with empty inputs, which return before the parsing loop, so its
ValueError branch was untested. Add tests that a field without "=" raises,
whether it is a bare name or an empty field (from a doubled, leading, or
trailing separator), for str and bytes. The empty-field case also covers the
guard that stops strict mode from silently skipping empty fields. Assert the
boundary too: a field is accepted whenever it contains "=", even with an empty
name or value, and well-formed input still parses.
@nikolauspschuetz
nikolauspschuetz force-pushed the test-parse-qsl-strict-parsing branch from ce9972e to 6a1628a Compare July 21, 2026 14:38
@bedevere-app

bedevere-app Bot commented Jul 21, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant