Skip to content

fix: expand variables in content type application/x-www-form-urlencoded #491

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

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions lua/rest-nvim/parser/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ function parser.parse_body(content_type, body_node, source, context)
if content_type and vim.startswith(content_type, "application/x-www-form-urlencoded") then
body.__TYPE = "raw"
body.data = parse_urlencoded_form(text)
body.data = expand_variables(body.data, context)
if not body.data then
logger.error("Error while parsing urlencoded form")
return nil
Expand Down
17 changes: 17 additions & 0 deletions spec/parser/http_parser_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,23 @@ Authorization: Bearer {{TOKEN}}
}]],
}, req.body)
end)
it("parse with variables in urlencoded body", function ()
vim.env["VAR"] = "variable"
local source = [[POST https://example.com
Content-Type: application/x-www-form-urlencoded

foo={{VAR}}
]]
local _, tree = utils.ts_parse_source(source)
local req_node = assert(tree:root():child(0))
local req = parser.parse(req_node, source)
assert.not_nil(req)
---@cast req rest.Request
assert.same({
__TYPE = "raw",
data = "foo=variable"
}, req.body)
end)
it("parse variable declaration", function()
local source = "@foo = bar\n"
local _, tree = utils.ts_parse_source(source)
Expand Down