Skip to content

Submitting empty form, or forms with only checkboxes, causes crash in web server #68

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

Closed
radair6000 opened this issue Sep 1, 2023 · 2 comments · Fixed by #67
Closed

Comments

@radair6000
Copy link

Hi,

I think I found an issue in the web server included in CircuitPython. If you post a form back to the web server that has no input fields, OR contains only chekboxes and they all are clear (which causes no form data to be posted back), the web server seems to crash.

For example this form:

<form action="/update" method="post">
    <input type="checkbox" name="test" value="1">
    <input type="submit" value="Update">
</form>

When the checkbox is clear, and the form is posted back, when trying to access the field value (or any of the other relevant methods like get(...)):

@server.route("/update", POST)
def update(request: Request):
    x = request.form_data.fields

The web server crashes with this error:

  File "adafruit_httpserver/request.py", line 321, in form_data
  File "adafruit_httpserver/request.py", line 144, in __init__
  File "adafruit_httpserver/request.py", line 157, in _parse_x_www_form_urlencoded
ValueError: need more than 1 values to unpack

This is using adafruit_httpserver from adafruit-circuitpython-bundle-8.x-mpy-20230829.zip on a Rasberry PI Pico on Circuit Python 8.2.4
If I add a text or hidden input in the form for example, it works:

<form action="/update" method="post">
    <input type="checkbox" name="test" value="1">
    <input type="hidden" name="a" value="1">
    <input type="submit" value="Update">
</form>
michalpokusa added a commit to michalpokusa/Adafruit_CircuitPython_HTTPServer that referenced this issue Sep 1, 2023
@michalpokusa
Copy link
Contributor

Hi, thanks for great explaining the source of the issue, I was able to track down the reason and the fix is included in the #67 PR. Thanks!

@radair6000
Copy link
Author

Managed to test this now (sorry for taking so long), and it seems to be working great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants