Skip to content

fix: handle empty string and keys without value in postData on /v1 endpoint (#1548) #1550

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

eZ4RK0
Copy link

@eZ4RK0 eZ4RK0 commented Jul 25, 2025

Fixes #1548

Summary:
The request.post method was failing on the /v1 endpoint when postData was an empty string.
Additionally, it fixes an IndexError occurring when a key without an associated value is provided in postData.
This PR changes the handling of postData to properly account for the empty-string case and keys without values.

Before :

query_string = req.postData if req.postData[0] != '?' else req.postData[1:]
pairs = query_string.split('&')
for pair in pairs:
    parts = pair.split('=')
    # noinspection PyBroadException
    try:
        name = unquote(parts[0])
    except Exception:
        name = parts[0]
    if name == 'submit':
        continue
    # noinspection PyBroadException
    try:
        value = unquote(parts[1])
    except Exception:
        value = parts[1]

After :

query_string = req.postData if req.postData and req.postData[0] != '?' else req.postData[1:] if req.postData else ''
pairs = query_string.split('&')
for pair in pairs:
    parts = pair.split('=', 1)
    # noinspection PyBroadException
    try:
        name = unquote(parts[0])
    except Exception:
        name = parts[0]
    if name == 'submit':
        continue
    # noinspection PyBroadException
    try:
        value = unquote(parts[1]) if len(parts) > 1 else ''
    except Exception:
        value = parts[1] if len(parts) > 1 else ''

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

Successfully merging this pull request may close these issues.

request.post fails on /v1 endpoint when postData is an empty string
2 participants