Closed rruizadame closed 7 years ago
Do you mean you have to explicitly escape the quotes on Windows? Since I don't have access to a Windows machine, could you paste the output in debug mode for unescaped quotes?
Hello diepm:
Yes, thank you, when I use it in windows, it shows the following message:
**Request:
http://localhost:3000 POST /account { "username":"aaa", "password":"aaa", "twitter":"aaa" }
**Response:
curl: no URL specified! curl: try 'curl --help' or 'curl --manual' for more information
**Request:
http://localhost:3000 POST /account { \"username\":\"aaa\", \"password\":\"aaa\", \"twitter\":\"aaa\" }
**Response:
HTTP/1.1 200 OK X-Powered-By: Express Content-Type: application/json; charset=utf-8 Content-Length: 51 ETag: W/"33-HHmtHndqe4nccthw2idBEg" Date: Thu, 31 Dec 2015 00:42:45 GMT Connection: keep-alive
{ "password": "aaa", "twitter": "aaa", "username": "aaa" }
I think the message does not help so much, this is the value of curlCmd before the 'system' instruction is called
curlCmd value:
curl -v -sS -i -H "Content-Type: application/json" --data "{""username"":""aaa"",""password"":""aaa"",""twitter"":""aaa""}" " http://localhost:3000/account"
at [...]
if vrcDebug
echom curlCmd
endif
silent !clear
redraw!
return system(curlCmd) <---- this is the value at this line (175
file:rest.vim) endfunction [...]
Thank you
Best regards.
Roberto Morales.
2015-12-28 19:20 GMT-06:00 diepm notifications@github.com:
Do you mean you have to explicitly escape the quotes on Windows? Since I don't have access to a Windows machine, could you paste the output in debug mode for unescaped quotes?
— Reply to this email directly or view it on GitHub https://github.com/diepm/vim-rest-console/issues/18#issuecomment-167690035 .
I couldn't think of what makes it fail on Windows. Probably I'll need to setup a Windows VM to reproduce it. However, this command looks suspicious to me.
curl -v -sS -i -H "Content-Type: application/json" --data "{""username"":""aaa"",""password"":""aaa"",""twitter"":""aaa""}" " http://localhost:3000/account"
I don't recall how Windows shell escapes the arguments. In the debug mode, if you don't escape the quotes, what is the output command (can be seen by :mess
after a run trigger)?
I've checked Vim's docs regarding shellescape()
function, it says that
shellescape({string} [, {special}]) shellescape()
Escape {string} for use as a shell command argument.
On MS-Windows and MS-DOS, when 'shellslash' is not set, it
will enclose {string} in double quotes and double all double
quotes within {string}.
:h shellslash
gives me
'shellslash' 'ssl' boolean (default off)
global
{not in Vi} {only for MSDOS, MS-Windows and OS/2}
When set, a forward slash is used when expanding file names. This is
useful when a Unix-like shell is used instead of command.com or
cmd.exe. Backward slashes can still be typed, but they are changed to
forward slashes by Vim.
Could you check/try shellslash
option?
I have the same problem and set shellslash
doesn't help.
Basically, what I try to do is:
http://localhost:8888
-i -sS
POST /portal/get_data
{"email": "test@gmail.com"}
and results are:
with shellslash
curl: (6) Could not resolve host: application
curl: (3) unmatched close brace/bracket in URL position 15:
test@gmail.com}'
^
curl: (3) URL using bad/illegal format or missing URL
and curl is
|| curl -H 'Content-Type: application/json' -i -sS -X POST --data '{"email": "test@gmail.com"}' 'http://localhost:8888/portal/get_data'
With noshellslash
curl: (3) unmatched close brace/bracket in URL position 15:
test@gmail.com} http://localhost:8888/portal/get_data
curl:
|| curl -H "Content-Type: application/json" -i -sS -X POST --data "{""email"": ""test@gmail.com""}" "http://localhost:8888/portal/get_data"
But for the
http://localhost:8888
-i -sS
POST /portal/get_data
{email: test@gmail.com}
everything works (note, no "" in the post data)
Also, if I manually change escaping to
curl -H "Content-Type: application/json" -i -sS -X POST --data "{\"email\": \"test@gmail.com\"}" "http://localhost:8888/portal/get_data"
it works for me from the command line.
So a quick and dirty fix (I am sure it doesn't cover all use cases :) ) is to change shell escapes to manual escapes:
for POST: line 559 in ftplugin/rest.vim
""" Otherwise, just join data using empty space.
" return '--data ' . shellescape(join(dataLines, ''))
return '--data "' . substitute(join(dataLines, ''), '"', '\\"', 'g') . '"'
I think it could be done for GET too? Not an expert :)
Better solution would be is to introduce s:ShellEscape function that will be used everywhere instead built in shellescape.
and in that function depending on OS you would escape smth like:
fun! s:shellescape(val)
if has("win32")
return '"'.substitute(a:val, '["&\\]', '\\&', 'g').'"'
else
return shellescape(a:val)
endif
endf
PS, not sure about symbols & and | whether they should be escaped in windows.
@diepm fyi
Could you check it on linux(?) or OSX(?). Just to be sure it didn't break anything for you.
This is a fantastic tool, and this is not really an issue but, when I use windows I have to escape the request JSON like this:
http://localhost/ POST /testService { \"id\" : 6 }
It would be nice not escaping quotes needed
Best Regards