1

The following command works in GNU Bash on FreeBSD but not in Git Bash on Windows:

curl -X PUT https://example.com/_config/cors/origins -d '"*"'

The intended result is to send a PUT request to https://example.com/_config/cors/origins with the body "*" (including the quotes - it's a JSON string).

However on Windows, the asterisk gets expanded as a glob even though it’s within quotes. Excerpt from --trace-ascii cURL log:

0000: PUT /_config/cors/origins HTTP/1.1
004f: User-Agent: curl/7.30.0
008e: Content-Length: 13
00a2: Content-Type: application/x-www-form-urlencoded
00d3: 
=> Send data, 13 bytes (0xd)
0000: .editorconfig
== Info: upload completely sent off: 13 out of 13 bytes

(.editorconfig is the first file in the current directory.)

Escaping with a backslash ('"\*"') transmits the backslash:

0000: PUT /_config/cors/origins HTTP/1.1
004f: User-Agent: curl/7.30.0
008e: Content-Length: 4
00a1: Content-Type: application/x-www-form-urlencoded
00d2: 
=> Send data, 4 bytes (0x4)
0000: "\*"
== Info: upload completely sent off: 4 out of 4 bytes

Two backslashes also transmits both backslashes in the request.

0000: PUT /_config/cors/origins HTTP/1.1
004f: User-Agent: curl/7.30.0
008e: Content-Length: 5
00a1: Content-Type: application/x-www-form-urlencoded
00d2: 
=> Send data, 5 bytes (0x5)
0000: "\\*"
== Info: upload completely sent off: 5 out of 5 bytes

Is this a bug?

Tamlyn
  • 310
  • 2
  • 11
  • I posted an answer but when you say, you used two backslashes can you actually edit your post to show us an example? Or perhaps just edit to show all the different ideas/attempts you made? That would be helpful from a debugging standpoint. – Giacomo1968 Apr 03 '15 at 21:19
  • Are you sure bash is the culprit and not curl? What curl are you using (native build or cygwin/msys one)? Some versions of libc for Windows will expand * (but not other globs) while parsing the command line (from `GetCommandLine` to argc/argv) -> can you test with cmd.exe (that passes the command line unchanged) if you can also see the "globbing"? – mihi Apr 04 '15 at 10:41
  • When using a `cmd` prompt I can get it to work by passing `-d \"*\"` – Tamlyn Apr 04 '15 at 12:31
  • and when you try `-d '\"*\"'` in bash, it does not work? – mihi Apr 04 '15 at 12:50
  • nope, it sends the backslashes too. – Tamlyn Apr 06 '15 at 15:30

1 Answers1

0

Try it like this idea based on escaping tips and ideas found on this site:

curl -X PUT https://example.com/_config/cors/origins -d "\*"

Another idea comes from this answer on a similar question about sending data via a POST request. First create a “data” file called “data.txt” that simply contains the *. Then run this curl command:

curl -X POST -d @data.txt https://example.com/_config/cors/origins

You could try that without the -X POST which sets the request method like this:

curl -d @data.txt https://example.com/_config/cors/origins
Giacomo1968
  • 53,069
  • 19
  • 162
  • 212