Skip to content

Commit d902996

Browse files
authored
Merge pull request #113 from srihari93/fix-#102
[FIX] /issues/102: some payloads can confuse rest.nvim
2 parents e5f68db + 33c6829 commit d902996

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lua/rest-nvim/request/init.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ local function get_importfile_name(bufnr, start_line, stop_line)
3636
end
3737

3838
-- get_body retrieves the body lines in the buffer and then returns
39-
-- either a raw string with the body if it is JSON, or a filename. Plenary.curl can distinguish
39+
-- either a table if the body is a JSON or a raw string if it is a filename
40+
-- Plenary.curl allows a table or a raw string as body and can distinguish
4041
-- between strings with filenames and strings with the raw body
4142
-- @param bufnr Buffer number, a.k.a id
4243
-- @param start_line Line where body starts
@@ -70,6 +71,11 @@ local function get_body(bufnr, start_line, stop_line)
7071
end
7172
end
7273

74+
local is_json, json_body = pcall(vim.fn.json_decode, body)
75+
if is_json then
76+
return json_body
77+
end
78+
7379
return body
7480
end
7581
-- is_request_line checks if the given line is a http request line according to RFC 2616

0 commit comments

Comments
 (0)