Skip to content

Commit

Permalink
fix(dotenv): allow hash inside quoted environment variables (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
boltlessengineer committed Feb 24, 2025
1 parent 98f0bfc commit 646439f
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lua/rest-nvim/parser/dotenv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,21 @@ function M.parse(path, setter)
end
else
-- TODO: rewrite the parser with tree-sitter-bash instead
local vars_tbl = vim.split(file_contents, "\n", { trimempty = true })
logger.debug(vars_tbl)
for _, var in ipairs(vars_tbl) do
local variable_name, variable_value = var:match("([^#=%s]+)%s*=%s*([^#]*)")
if variable_name then
variable_value = variable_value:match('^"(.*)"$') or variable_value:match("^'(.*)'$") or variable_value
logger.debug("set " .. variable_name .. "=" .. variable_value)
setter(variable_name, value_tostring(variable_value))
end
end
local lines = vim.split(file_contents, "\n", { trimempty = true })
logger.debug(lines)
vim.iter(lines)
:filter(function(line)
return not line:match("^%s*#")
end)
:map(function(line)
return line:match("^export%s*(.*)") or line
end)
:each(function(line)
local name, value = line:match("([^#=%s]+)%s*=%s*(.*)")
if name then
setter(name, value:match('^"([^"]*)"$') or value:match("^'([^']*)'$") or value:match("([^%s#]*)"))
end
end)
end
return true, vars
end
Expand Down

0 comments on commit 646439f

Please sign in to comment.