Skip to content

Commit 646439f

Browse files
fix(dotenv): allow hash inside quoted environment variables (#514)
1 parent 98f0bfc commit 646439f

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

lua/rest-nvim/parser/dotenv.lua

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,21 @@ function M.parse(path, setter)
6363
end
6464
else
6565
-- TODO: rewrite the parser with tree-sitter-bash instead
66-
local vars_tbl = vim.split(file_contents, "\n", { trimempty = true })
67-
logger.debug(vars_tbl)
68-
for _, var in ipairs(vars_tbl) do
69-
local variable_name, variable_value = var:match("([^#=%s]+)%s*=%s*([^#]*)")
70-
if variable_name then
71-
variable_value = variable_value:match('^"(.*)"$') or variable_value:match("^'(.*)'$") or variable_value
72-
logger.debug("set " .. variable_name .. "=" .. variable_value)
73-
setter(variable_name, value_tostring(variable_value))
74-
end
75-
end
66+
local lines = vim.split(file_contents, "\n", { trimempty = true })
67+
logger.debug(lines)
68+
vim.iter(lines)
69+
:filter(function(line)
70+
return not line:match("^%s*#")
71+
end)
72+
:map(function(line)
73+
return line:match("^export%s*(.*)") or line
74+
end)
75+
:each(function(line)
76+
local name, value = line:match("([^#=%s]+)%s*=%s*(.*)")
77+
if name then
78+
setter(name, value:match('^"([^"]*)"$') or value:match("^'([^']*)'$") or value:match("([^%s#]*)"))
79+
end
80+
end)
7681
end
7782
return true, vars
7883
end

0 commit comments

Comments
 (0)