Skip to content

Commit 4eb74dc

Browse files
fix: expand variables in content type application/x-www-form-urlencoded (#491)
* fix: expand variables in content type application/x-www-form-urlencoded * fix: expand variables after parsing urlencoded body --------- Co-authored-by: Seongmin Lee <boltlessengineer@gmail.com>
1 parent 113dce7 commit 4eb74dc

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lua/rest-nvim/parser/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ function parser.parse_body(content_type, body_node, source, context)
182182
if content_type and vim.startswith(content_type, "application/x-www-form-urlencoded") then
183183
body.__TYPE = "raw"
184184
body.data = parse_urlencoded_form(text)
185+
body.data = expand_variables(body.data, context)
185186
if not body.data then
186187
logger.error("Error while parsing urlencoded form")
187188
return nil

spec/parser/http_parser_spec.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,23 @@ Authorization: Bearer {{TOKEN}}
326326
}]],
327327
}, req.body)
328328
end)
329+
it("parse with variables in urlencoded body", function ()
330+
vim.env["VAR"] = "variable"
331+
local source = [[POST https://example.com
332+
Content-Type: application/x-www-form-urlencoded
333+
334+
foo={{VAR}}
335+
]]
336+
local _, tree = utils.ts_parse_source(source)
337+
local req_node = assert(tree:root():child(0))
338+
local req = parser.parse(req_node, source)
339+
assert.not_nil(req)
340+
---@cast req rest.Request
341+
assert.same({
342+
__TYPE = "raw",
343+
data = "foo=variable"
344+
}, req.body)
345+
end)
329346
it("parse variable declaration", function()
330347
local source = "@foo = bar\n"
331348
local _, tree = utils.ts_parse_source(source)

0 commit comments

Comments
 (0)