Skip to content

Commit

Permalink
fix: proper regex for env variables and json body detecting
Browse files Browse the repository at this point in the history
  • Loading branch information
NTBBloodbath committed Jun 30, 2021
1 parent c6aed27 commit 850f01e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lua/rest-nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ local function get_headers(bufnr, query_line)
end

for _, next_line_content in pairs(next_line) do
if string.find(next_line_content, '{') then
-- If the next line starts the request body then break the loop
if next_line_content:find('^{') then
break_loops = true
break
else
Expand Down
4 changes: 2 additions & 2 deletions lua/rest-nvim/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ end
M.replace_env_vars = function(str)
local env_vars = M.read_env_file()

for var in string.gmatch(str, '{{%w+}}') do
for var in string.gmatch(str, '{{[%w%W]+}}') do
var = var:gsub('{', ''):gsub('}', '')
-- If the env variable wasn't found in the `.env` file then search it
-- in the OS environment variables
if M.has_key(env_vars, var) then
str = str:gsub('{{' .. var .. '}}', env_vars[var])
else
if os.getenv(var) ~= nil then
if os.getenv(var) then
str = str:gsub('{{' .. var .. '}}', os.getenv(var))
else
error(
Expand Down

0 comments on commit 850f01e

Please sign in to comment.