Skip to content

Commit 850f01e

Browse files
committed
fix: proper regex for env variables and json body detecting
1 parent c6aed27 commit 850f01e

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lua/rest-nvim/init.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ local function get_headers(bufnr, query_line)
126126
end
127127

128128
for _, next_line_content in pairs(next_line) do
129-
if string.find(next_line_content, '{') then
129+
-- If the next line starts the request body then break the loop
130+
if next_line_content:find('^{') then
130131
break_loops = true
131132
break
132133
else

lua/rest-nvim/utils/init.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ end
3232
M.replace_env_vars = function(str)
3333
local env_vars = M.read_env_file()
3434

35-
for var in string.gmatch(str, '{{%w+}}') do
35+
for var in string.gmatch(str, '{{[%w%W]+}}') do
3636
var = var:gsub('{', ''):gsub('}', '')
3737
-- If the env variable wasn't found in the `.env` file then search it
3838
-- in the OS environment variables
3939
if M.has_key(env_vars, var) then
4040
str = str:gsub('{{' .. var .. '}}', env_vars[var])
4141
else
42-
if os.getenv(var) ~= nil then
42+
if os.getenv(var) then
4343
str = str:gsub('{{' .. var .. '}}', os.getenv(var))
4444
else
4545
error(

0 commit comments

Comments
 (0)