Skip to content

Commit

Permalink
fix: correct uri scheme parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
boltlessengineer committed Jan 1, 2025
1 parent 5455092 commit 62606c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lua/rest-nvim/client/curl_cli.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local curl_cli = require("rest-nvim.client.curl.cli")
local logger = require("rest-nvim.logger")

local COMPATIBLE_METHODS = {
"OPTIONS",
Expand All @@ -20,8 +21,9 @@ local client = {
request = curl_cli.request,
available = function(req)
local method_ok = vim.list_contains(COMPATIBLE_METHODS, req.method)
local scheme = req.url:match("^(.+)://")
local scheme = req.url:match("^([^:]+)://")
local scheme_ok = (not scheme) or scheme == "http" or scheme == "https"
logger.debug(("scheme %s not supported for curl_cli client"):format(scheme or "<nil>"))
return method_ok and scheme_ok
end,
}
Expand Down
17 changes: 17 additions & 0 deletions spec/client/client_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---@module 'luassert'

local clients = require("rest-nvim.client")

describe("request clients", function()
it("get_available_clients", function()
local req = {
method = "GET",
url = "https://duckduckgo.com?q=https://duckduckgo.com",
headers = {},
cookies = {},
handlers = {},
}
local available_clients = clients.get_available_clients(req)
assert.same(1, #available_clients)
end)
end)

0 comments on commit 62606c3

Please sign in to comment.