rest.nvim icon indicating copy to clipboard operation
rest.nvim copied to clipboard

Space encoding from + to %20, or user choice

Open Cozidian opened this issue 1 year ago • 3 comments

Im currently working with a unreasonable(maybe) strict api, and it will not accept space encoded to +, only when encoded to %20. I suggest to either always use %20 encoding for space, or maybe make it a configuration for the users to set?

-- encode_url encodes the given URL
-- @param url The URL to encode
M.encode_url = function(url)
  if url == nil then
    error("You must need to provide an URL to encode")
  end

  url = url:gsub("\n", "\r\n")
  -- Encode characters but exclude `.`, `_`, `-`, `:`, `/`, `?`, `&`, `=`, `~`, `@`
  url = string.gsub(url, "([^%w _ %- . : / ? & = ~ @])", M.char_to_hex)
  url = url:gsub(" ", "+") // this line could be changed to url = url:gsub(" ", "%%20") if you want to go with a hard change.
  return url
end

It is up to what direction you would like to take 😄

Cozidian avatar Feb 08 '24 20:02 Cozidian

Hi, I don't know how I lost this issue among my notifications. Sorry for the late reply!

If %20 is much more common and standardized (and does not create conflicts with APIs that use +) then we can easily switch to that proposal :)

Edit: I just did a quick search and it looks like HTTP will make us backflip. Since this may take me a bit of time, is it okay to address this issue in the dev branch? Making changes to the main branch and cherry-picks manually to dev thanks to the internal code changes (absolutely everything changed so I can't just patch on that branch hah) are wearing me out a little and delaying the release of the new version 😅

NTBBloodbath avatar Mar 15 '24 06:03 NTBBloodbath

@Cozidian could you send me what the URL to which you are sending the requests looks like? If you want to cover the foobar.com or send dummy text instead it's fine, the only relevant thing is to see the path and the parameters of the request, since the use of %20 or + heavily depends on this

NTBBloodbath avatar Mar 17 '24 08:03 NTBBloodbath

I need to retest this issue now after the new version is out. You can put this issue on hold in the meanwhile if you want :)

Cozidian avatar Mar 27 '24 14:03 Cozidian

Since v3 release, rest.nvim provides some User autocmd events to modify the request/response content. You can turn off default encode_url option from config and make your own encoder hook. See :help RestRequestPre.

boltlessengineer avatar Aug 23 '24 16:08 boltlessengineer