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 url parsing bug #153

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions lua/kulala/parser/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,41 @@ local function parse_headers(headers, variables, env)
end

local function encode_url_params(url)
local url_parts = vim.split(url, "?")
url = url_parts[1]
local query = url_parts[2]
local anchor = ""
local index = url:find("#")
if index then
anchor = "#" .. STRING_UTILS.url_encode(url:sub(index+1))
url = url:sub(1, index-1)
end
index = url:find("?")
if index == nil then
return url .. anchor
end
local query = url:sub(index+1)
url = url:sub(1, index-1)
local query_parts = {}
if query then
query_parts = vim.split(query, "&")
end
local query_params = ""
for _, query_part in ipairs(query_parts) do
local query_param = vim.split(query_part, "=")
query_params = query_params
.. "&"
.. STRING_UTILS.url_encode(query_param[1])
.. "="
.. STRING_UTILS.url_encode(query_param[2])
index = query_part:find("=")
if index then
query_params = query_params
.. "&"
.. STRING_UTILS.url_encode(query_part:sub(1, index-1))
.. "="
.. STRING_UTILS.url_encode(query_part:sub(index+1))
else
query_params = query_params
.. "&"
.. STRING_UTILS.url_encode(query_part)
end
end
if query_params ~= "" then
return url .. "?" .. query_params:sub(2)
url = url .. "?" .. query_params:sub(2)
end
return url
return url .. anchor
end

local function parse_url(url, variables, env)
Expand Down