Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve blank form values for urlencoded forms (option) #2439

Merged
merged 10 commits into from Apr 24, 2022
Merged

Conversation

sjsadowski
Copy link
Contributor

This is a non-breaking update to form parsing based on a realistic expectation of being able to preserve blank values that are passed. As this currently works, using the default behavior of urllib.parse_qs, blank values are dropped, however this is sometimes not the preferred behavior. urllib.parse_qs has a parameter (keep_blank_values) that defaults to false, but can be set to true to ensure this is available. This fix allows for that option to be used by creating a new request property that can be updated.

closes #2427

refactor logic from the .form property to .get_form() method which will accept the optional parameter of keep_blank_values as a boolean. By default this is False, preserving the existing behavior. If set to True, will preserve blank values in x-www-form-urlencoded forms when request.form is accessed

New tests:
form keep blanks
form drop blanks (expected behavior)

@sjsadowski sjsadowski requested a review from a team as a code owner April 24, 2022 13:26
@codecov
Copy link

codecov bot commented Apr 24, 2022

Codecov Report

Merging #2439 (481cd4c) into main (3a6cc73) will increase coverage by 0.007%.
The diff coverage is 100.000%.

@@              Coverage Diff              @@
##              main     #2439       +/-   ##
=============================================
+ Coverage   87.138%   87.145%   +0.007%     
=============================================
  Files           60        60               
  Lines         5046      5049        +3     
  Branches       908       908               
=============================================
+ Hits          4397      4400        +3     
  Misses         477       477               
  Partials       172       172               
Impacted Files Coverage Δ
sanic/request.py 96.264% <100.000%> (+0.032%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3a6cc73...481cd4c. Read the comment docs.

sanic/request.py Outdated Show resolved Hide resolved
@ahopkins ahopkins merged commit 78b6723 into main Apr 24, 2022
@ahopkins ahopkins deleted the 2427-get-form branch April 24, 2022 20:01
ChihweiLHBird pushed a commit to ChihweiLHBird/sanic that referenced this pull request Jun 1, 2022
)

* task(request.form): Add tests for blank values

* fix(request): abstract form property to implement get_form(), allow for preserving of blanks

* fix(request): hinting for parsed_form

* fix(request): typing for parsed_files

* fix(request): ignore type assumption

* fix(request): mypy typechecking caused E501 when type set to ignore

* fix(request): mypy is too stupid to parse continuations

* fix(request): formatting

* fix(request): fix annotation and return for get_form()

* fix(request): linting, hinting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants