Skip to content

Commit f031bef

Browse files
authored
fix(curl): Do not reuse URL from previous call (#602)
Previously the URL could be accidentally reused between requests. local curl = require "plenary.curl" curl.get("url", { dry_run = true }) -- { ..., "-X", "GET", "url" } curl.get({ dry_run = true }) -- { ..., "-X", "GET", "url" }
1 parent e6dcd56 commit f031bef

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lua/plenary/curl.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,9 @@ end
332332
-- Main ----------------------------------------------------
333333
------------------------------------------------------------
334334
return (function()
335-
local spec = {}
336335
local partial = function(method)
337336
return function(url, opts)
337+
local spec = {}
338338
opts = opts or {}
339339
if type(url) == "table" then
340340
opts = url

tests/plenary/curl_spec.lua

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,26 @@ describe("CURL Wrapper:", function()
196196
end)
197197
end)
198198

199-
describe("DEPUG", function() --------------------------------------------------
199+
describe("DEBUG", function() --------------------------------------------------
200200
it("dry_run return the curl command to be ran.", function()
201201
local res = curl.delete("https://jsonplaceholder.typicode.com/posts/8", { dry_run = true })
202202
assert(type(res) == "table")
203203
end)
204204
end)
205+
206+
describe("Issue #601", function() --------------------------------------------
207+
it("should not use URL from previous call", function()
208+
local url = "https://example.com"
209+
local opts = { dry_run = true, dump = "" } -- dump would be random each time
210+
local first = curl.get(url, opts)
211+
eq(table.remove(first, #first), url, "expected url last")
212+
213+
local success, second = pcall(curl.get, opts)
214+
if success then
215+
eq(first, second, "should be same, but without url")
216+
else
217+
-- Failure is also acceptable
218+
end
219+
end)
220+
end)
205221
end)

0 commit comments

Comments
 (0)