Repository navigation
gh-158225: Fix wsgiref Headers __setitem__ validation order - #158226
Tony123-tech wants to merge 1 commit into
Conversation
4666fad to
91d9761
Compare
91d9761 to
cabcc7d
Compare
|
Hi! I reviewed and tested this change locally. Specifically, I checked that when validation of the new header name or value fails, the existing header value is preserved: from wsgiref.headers import Headers
h = Headers([("Content-Type", "text/html")])
try:
h["Content-Type"] = True
except AssertionError:
pass
assert h.get("Content-Type") == "text/html"I also checked the case where validation of the header name fails because it contains a control character: from wsgiref.headers import Headers
h = Headers([("Content-Type", "text/html")])
try:
h["Content-\x00Type"] = "application/json"
except ValueError:
pass
assert h.get("Content-Type") == "text/html"In both cases, the existing header remains unchanged. I also ran the relevant test suite: I didn't find any issues with the change in these checks. |
|
Good question. The realistic case is middleware or frameworks that build headers from user input. If a caller passes a non-string value (e.g. int, None) — which happens with sloppy request parsing — the current code silently drops the existing header rather than raising before mutating. That's the "surprising mutation on failure" pattern. If you'd prefer not to change behavior, I'm fine closing the PR. Otherwise the fix is small and validated. |
|
Fair enough — I don't have a real-world case. Closing this. Thanks for the review |
Uh oh!
There was an error while loading. Please reload this page.