Skip to content

Commit 910ff9e

Browse files
committed
fix(curl): Do not reuse URL from previous call
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 0aa9ce3 commit 910ff9e

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

lua/plenary/curl.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ end
322322
-- Main ----------------------------------------------------
323323
------------------------------------------------------------
324324
return (function()
325-
local spec = {}
326325
local partial = function(method)
327326
return function(url, opts)
327+
local spec = {}
328328
opts = opts or {}
329329
if type(url) == "table" then
330330
opts = url

tests/plenary/curl_spec.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,20 @@ describe("CURL Wrapper:", function()
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)