Skip to content

Commit 6af0022

Browse files
fix(parser): remove line breaks from url
1 parent 0ba1c60 commit 6af0022

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

lua/rest-nvim/parser/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ function parser.parse(node, source, ctx)
292292
ctx,
293293
utils.escape
294294
)
295+
url = url:gsub("\n%s+", "")
295296

296297
local name
297298
local handlers = {}

spec/examples/multi_line_url.http

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### multi-line url
2+
// reference: https://www.jetbrains.com/help/idea/exploring-http-syntax.html#break-long-requests-into-several-lines
3+
// Using line breaks with indent
4+
GET http://example.com:8080
5+
/api
6+
/html
7+
/get
8+
?id=123
9+
&value=content

spec/examples_spec.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---@module 'luassert'
2+
3+
require("spec.minimum_init")
4+
5+
local parser = require("rest-nvim.parser")
6+
local utils = require("rest-nvim.utils")
7+
8+
local function open(path)
9+
vim.cmd.edit(path)
10+
vim.cmd.source("ftplugin/http.lua")
11+
return 0
12+
end
13+
14+
describe("multi-line-url", function ()
15+
it("line breaks should be ignored", function ()
16+
local source = open("spec/examples/multi_line_url.http")
17+
local _, tree = utils.ts_parse_source(source)
18+
local req_node = assert(tree:root():child(0))
19+
local req = parser.parse(req_node, source)
20+
assert(req)
21+
assert.same("http://example.com:8080/api/html/get?id=123&value=content", req.url)
22+
end)
23+
end)

0 commit comments

Comments
 (0)