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

Invalid Request Parsing #746

Closed
yubarajshrestha opened this issue Mar 14, 2023 · 0 comments · Fixed by #747
Closed

Invalid Request Parsing #746

yubarajshrestha opened this issue Mar 14, 2023 · 0 comments · Fixed by #747
Labels

Comments

@yubarajshrestha
Copy link
Contributor

Describe the bug

When there's a single item in an array or dictionary, masonite converts it into normal form like string or number. Take a look at the following example of a POST request.

For eg:

{
    "name": "Family",
    "contacts": [ "User One" ]
}

The above request gives an invalid record in the controller. Take a look at the response:

# controller
def my_controller(self, request: Request):
    data = request.all()

The above data has the following data in it, which is wrong because the user is expecting an array there.

{
    "name": "Family",
    "contacts": "User One"
}

Expected behaviour

The correct response should be something like the below:

{
    "name": "Family",
    "contacts": [
        "User One"
    ]
}

Steps to reproduce the bug

  1. Post the following data in your post route:
{
    "name": "Family",
    "contacts": ["User One"]
}
  1. Check the response, you'll get the wrong response, which should look like this:
{
    "name": "Family",
    "contacts": "User One"
}
  1. But the response should be like this:
{
    "name": "Family",
    "contacts": ["User One"]
}

Screenshots

No response

OS

macOS

OS version

Ventura 13.2.1

Browser

No response

Masonite Version

4.17.4

Anything else ?

Yes, the above issue persists in all data types. I mean if there's an array of dictionaries and has only one item in it then: it will return one dictionary only instead of an array of a dictionary.

Request example:

{
    "name": "Family",
    "contacts": [{
        "name": "User One"
    }]
}

Current Response

{
    "name": "Family",
    "contacts": {
        "name": "User One"
    }
}

Expected Response

{
    "name": "Family",
    "contacts": [
        {
            "name": "User One"
        }
    ]
}
@yubarajshrestha yubarajshrestha changed the title Invalid JSON Post Parsing Invalid Request Parsing Mar 14, 2023
yubarajshrestha added a commit to yubarajshrestha/masonite that referenced this issue Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant