Skip to content

Commit

Permalink
fix: expand variables in content type application/x-www-form-urlencod…
Browse files Browse the repository at this point in the history
…ed (#491)

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

* fix: expand variables after parsing urlencoded body

---------

Co-authored-by: Seongmin Lee <[email protected]>
  • Loading branch information
kvrohit and boltlessengineer authored Nov 9, 2024
1 parent 113dce7 commit 4eb74dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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

0 comments on commit 4eb74dc

Please sign in to comment.