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 pattern allows to parse invalid queries #28

Open
GitSparTV opened this issue Oct 22, 2024 · 0 comments
Open

Invalid pattern allows to parse invalid queries #28

GitSparTV opened this issue Oct 22, 2024 · 0 comments

Comments

@GitSparTV
Copy link

for key,val in str:gmatch(string.format('([^%q=]+)(=*[^%q=]*)', sep, sep)) do

In this line string.format formats separator (which is & by default) using %q. %q specifier formats string such as it can be read by Lua interpreter. The final pattern will be ([^"&"=]+)(=*[^"&"=]*). gmatch is not a Lua interpreter and double quote in [] pattern will match any character but & or " (See the description). This is crucial because now " is also a valid separator.

local v = url.parse("http://example.com/?a=b\"c=d")

This code parses URL as this:

{
        host    =       example.com,
        authority       =       example.com,
        scheme  =       http,
        path    =       /,
        query   =       {
                        a       =       b,
                        c       =       d,
                }

}

But it's definitely wrong.

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

No branches or pull requests

1 participant