Skip to content

Commit fb35b85

Browse files
committed
fix: proper comments parsing regex. Closes #29
1 parent 850f01e commit fb35b85

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lua/rest-nvim/init.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ local function get_body(bufnr, stop_line, query_line, json_body)
8484
)
8585

8686
for _, json_line in ipairs(json_lines) do
87-
if not json_line:find('^%s+#') then
87+
-- Ignore commented lines with and without indent
88+
if not (json_line:find('^#') or json_line:find('^%s+#')) then
8889
json_string = json_string .. utils.replace_env_vars(json_line)
8990
end
9091
end
@@ -147,7 +148,7 @@ local function get_headers(bufnr, query_line)
147148
and not header[1]:find('^%s+"')
148149
-- If header key doesn't contains hashes,
149150
-- so we don't get commented headers
150-
and not header[1]:find('^%s+#')
151+
and not (header[1]:find('^#') or header[1]:find('^%s+#'))
151152
-- If header key doesn't contains HTTP methods,
152153
-- so we don't get the http method/url
153154
and not utils.has_value(http_methods, header[1])
@@ -186,7 +187,8 @@ local function get_accept(bufnr, query_line)
186187
)
187188

188189
for _, accept_data in pairs(accept_line) do
189-
if not accept_data:find('^%s+#') then
190+
-- Ignore commented lines with and without indent
191+
if not (accept_data:find('^#') or accept_data:find('(^%s+#)')) then
190192
accept = utils.split(accept_data, ':')[2]
191193
end
192194
end

0 commit comments

Comments
 (0)