Closed WrathOP closed 4 months ago
I am dumb or this is anyways keep this issue as someone might find this useful
{
// other fields
"access": ["8399BR", "8620MH"]
}
is the output
Now the problem is how can I send it like this from the frontend, its flutter
http.patch method wants its body as a Map<string,string> and then converts that into FormData for the request.
So basically I would need to have a write custom encoding?
With the code you provided (added one additional log to be sure) I ran this curl and it appeared to work correctly:
curl "http://localhost:3000/projects?filter=$(node -p 'encodeURIComponent(JSON.stringify({ projectCode: [1,2] }))')"
$ node index.js
Server is running on port 3000
Raw Filter: {"projectCode":[1,2]}
Filter: { projectCode: [ 1, 2 ] }
Update: {}
We do not provide general technical support on issues like this, but afaict this is not a bug in this package.
I guess I may have expressed myself unclearly. What I initially thought was a bug turned out to be an unusual implementation of how FormData handles arrays. The code snippet you showcased isn't related to my issue. The query is parsed correctly; the problem is actually with the form data. However, I don't want to bother the maintainers.
PS: I just realised how badly written my case is, no wonder he thought I was talking about the query not being parsed correctly.
Haha, ok sorry for the confusion, but glad to see you are working it out.
Description:
I am experiencing an issue with
body-parser
when attempting to parse a URL-encoded JSON string in the request body. Despite using thebody-parser.urlencoded()
middleware, the JSON string is not being parsed correctly into an array of strings on the server.Environment:
Steps to Reproduce:
Install Dependencies:
Backend Setup:
Curl Command:
Expected Behavior: The
access
field should be parsed as an array of strings.Actual Behavior: The
access
field is being stored as a single string:Additional Information: The body-parser middleware is expected to parse URL-encoded data correctly, but it seems to struggle with parsing JSON strings into arrays. This issue significantly impacts my application as the data format is critical for backend processing. I have tried using body-parser.json(), but I am constrained to using application/x-www-form-urlencoded due to frontend requirements. Workaround: As a workaround, I manually parse the access field from a JSON string within the request handler, which is not ideal and clutters the route logic.