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

Fix query parsing when value has = characters #1822

Merged
merged 5 commits into from
Apr 21, 2024

Conversation

jimmy-park
Copy link
Contributor

The current query parser handles "?a=b=c&..." as ("a", "c") which should be ("a", "b=c").
We should not use split() when parsing query strings.
So I need to implement a string divider which just splits in half.
Here are possible outcomes of the string divider.

divide("", '=')      -> ("", "")
divide("=", '=')     -> ("", "")
divide(" ", '=')     -> (" ", "")
divide("a", '=')     -> ("a", "")
divide("a=", '=')    -> ("a", "")
divide("=b", '=')    -> ("", "b")
divide("a=b", '=')   -> ("a", "b")
divide("a=b=", '=')  -> ("a", "b=")
divide("a=b=c", '=') -> ("a", "b=c")

Note

Whitespaces aren't trimmed!

@yhirose
Copy link
Owner

yhirose commented Apr 19, 2024

@jimmy-park thanks for the pull request and the code looks good to me. Where do you find the information of "?a=b=c&..." in the HTML spec or RFCs?

@jimmy-park
Copy link
Contributor Author

@yhirose RFC does not specify the format of query. Any string between '?' and '#' could be a query . I think key=value pair is just a well known convention that people use.
https://datatracker.ietf.org/doc/html/rfc3986#section-3.4

And I've seen some queries with '=' in the value actually being used at work.

@yhirose
Copy link
Owner

yhirose commented Apr 21, 2024

@jimmy-park, ok. Could you please check how other HTTP libraries handle these queries? If they do the same, I have no issue with this pull request.

@jimmy-park
Copy link
Contributor Author

@yhirose I found one.
https://github.com/drogonframework/drogon/blob/96919df488e0ebaa0ed304bbd76bba33508df3cc/lib/src/HttpRequestImpl.cc#L145-L163

@yhirose yhirose merged commit 3b6597b into yhirose:master Apr 21, 2024
4 checks passed
@yhirose
Copy link
Owner

yhirose commented Apr 21, 2024

@jimmy-park thanks for the improvement!

@jimmy-park jimmy-park deleted the fix-query-parsing branch April 22, 2024 03:19
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.

None yet

2 participants