From 3054ca24c8ae0bc30d35fa88d64d9f50bbe43496 Mon Sep 17 00:00:00 2001 From: Juho Eerola Date: Tue, 9 Jul 2024 17:14:13 +0300 Subject: [PATCH 1/2] Fix typo --- tests/plenary/curl_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plenary/curl_spec.lua b/tests/plenary/curl_spec.lua index c268492fe..c9d73e801 100644 --- a/tests/plenary/curl_spec.lua +++ b/tests/plenary/curl_spec.lua @@ -196,7 +196,7 @@ describe("CURL Wrapper:", function() end) end) - describe("DEPUG", function() -------------------------------------------------- + describe("DEBUG", function() -------------------------------------------------- it("dry_run return the curl command to be ran.", function() local res = curl.delete("https://jsonplaceholder.typicode.com/posts/8", { dry_run = true }) assert(type(res) == "table") From 3d3b823ac0db7e306906cb808c96d5453ab7c430 Mon Sep 17 00:00:00 2001 From: Juho Eerola Date: Tue, 9 Jul 2024 17:14:24 +0300 Subject: [PATCH 2/2] 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" } --- lua/plenary/curl.lua | 2 +- tests/plenary/curl_spec.lua | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lua/plenary/curl.lua b/lua/plenary/curl.lua index 20e8cc270..321bed8a5 100644 --- a/lua/plenary/curl.lua +++ b/lua/plenary/curl.lua @@ -332,9 +332,9 @@ end -- Main ---------------------------------------------------- ------------------------------------------------------------ return (function() - local spec = {} local partial = function(method) return function(url, opts) + local spec = {} opts = opts or {} if type(url) == "table" then opts = url diff --git a/tests/plenary/curl_spec.lua b/tests/plenary/curl_spec.lua index c9d73e801..c4ba89aab 100644 --- a/tests/plenary/curl_spec.lua +++ b/tests/plenary/curl_spec.lua @@ -202,4 +202,20 @@ describe("CURL Wrapper:", function() assert(type(res) == "table") end) end) + + describe("Issue #601", function() -------------------------------------------- + it("should not use URL from previous call", function() + local url = "https://example.com" + local opts = { dry_run = true, dump = "" } -- dump would be random each time + local first = curl.get(url, opts) + eq(table.remove(first, #first), url, "expected url last") + + local success, second = pcall(curl.get, opts) + if success then + eq(first, second, "should be same, but without url") + else + -- Failure is also acceptable + end + end) + end) end)