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

square brackets confuse the parser #513

Open
manuxio opened this issue Oct 10, 2024 · 5 comments
Open

square brackets confuse the parser #513

manuxio opened this issue Oct 10, 2024 · 5 comments

Comments

@manuxio
Copy link

manuxio commented Oct 10, 2024

Hello,
while parsing a body like the following, qs fails:

buttons[commands.identifier_orders_merge_action|{"orders":["47441","47440"]}]=Unisci+ordini

This becomes something like:

'buttons[commands.identifier_orders_merge_action|{"orders":': { '"47441","47440"': 'Unisci ordini' }

while it should be something more similar to this:

'buttons[commands.identifier_orders_merge_action|{"orders":{ '"47441","47440"}]': 'Unisci ordini'

@ljharb
Copy link
Owner

ljharb commented Oct 10, 2024

I agree this is mis-parsed, but why are you using | as a delimiter, and why are you sending JSON in a query string??

@manuxio
Copy link
Author

manuxio commented Oct 10, 2024

I don't think this really matters...
Anyway... "|" is as good as any other delimiter.
It's not used in a querystring, it's used in a post field.
I found the bug while using body-parser.

Why is it json?
Couldn't think of anything better to carry some data in the property name of an object.

I need the final object to look like this:

{
"propName": "value"
}

one single prop. No more.

the only way to carry some data is to put in the propName (value is limited to 20 chars)

Oh, well, its a long story... I might encode the json string... but the bug would still persist!

m.

@ljharb
Copy link
Owner

ljharb commented Oct 11, 2024

would [propName]=value work?

@manuxio
Copy link
Author

manuxio commented Oct 11, 2024

As long as propName has no limit to what characters it can contain.
If propName can be: "my name|{"data":["one","two","three"]}" then it's ok with me.
I don't think there should be any constraint.
If a propName works in js, it should be parsable by qs.

@ljharb
Copy link
Owner

ljharb commented Oct 11, 2024

It has some limits that are due to the browser's query string standards, and that, not JS, determines what must work or not.

It looks like the square and curly brackets are what causes issues here, since '[my name|{"data":["one","two","three"]}]=value' parses to { '[my name|{"data":': { '"one","two","three"': 'value' } }.

Additionally, if you start with the JS object you want, then { 'my name|{"data":["one","two","three"]}': 'value' } stringifies to 'my%20name%7C%7B%22data%22%3A%5B%22one%22%2C%22two%22%2C%22three%22%5D%7D=value' which does not successfully round trip. In other words, while the exact string contents of the query string aren't necessarily as permitting as you want them to be, the lack of a round trip here is indeed a bug that needs fixing.

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

No branches or pull requests

2 participants