Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verbose/writeout.md: clarify Windows % symbol escaping #279

Closed
wants to merge 1 commit into from

Conversation

jay
Copy link
Member

@jay jay commented Jan 23, 2023

  • Clarify that in Windows batch files the % must be escaped as %%, and at the command prompt it cannot be escaped which could lead to incorrect expansion.

Prior to this change the doc implied % must be escaped as %% in win32 always.


Examples:

If curl --write-out "%{http_code}" is executed in a batch file: {http_code}

If curl --write-out "%%{http_code}" is executed in a batch file: %{http_code}

If curl --write-out "%{http_code}" is executed from the command prompt: %{http_code}

If curl --write-out "%%{http_code}" is executed from the command prompt: %%{http_code}

At the command prompt something like "%{speed_download}%{http_code}" would first be parsed by the command interpreter as %{speed_download}% and would be expanded as environment variable {speed_download} if it existed, though that's highly unlikely since Windows environment names don't use braces.


Reported-by: Muhammad Hussein Ammari

Ref: curl/curl#10337

Fixes curl/curl#10323
Closes #xxxx

- Clarify that in Windows batch files the % must be escaped as %%, and
  at the command prompt it cannot be escaped which could lead to
  incorrect expansion.

Prior to this change the doc implied % must be escaped as %% in win32
always.

---

Examples:

If curl --write-out "%{http_code}" is executed in a batch file:
{http_code}

If curl --write-out "%%{http_code}" is executed in a batch file:
%{http_code}

If curl --write-out "%{http_code}" is executed from the command prompt:
%{http_code}

If curl --write-out "%%{http_code}" is executed from the command prompt:
%%{http_code}

At the command prompt something like "%{speed_download}%{http_code}"
would first be parsed by the command interpreter as %{speed_download}%
and would be expanded as environment variable {speed_download} if it
existed, though that's highly unlikely since Windows environment names
don't use braces.

---

Reported-by: Muhammad Hussein Ammari

Ref: curl/curl#10337

Fixes curl/curl#10323
Closes #xxxx
@jay jay mentioned this pull request Jan 23, 2023
@dfandrich
Copy link
Collaborator

dfandrich commented Jan 23, 2023 via email

@jay
Copy link
Member Author

jay commented Jan 23, 2023

No, it doesn't need escaping in powershell. Note that in Windows 10 & 11 powershell uses the name 'curl' as an alias for Invoke-WebRequest cmdlet which is confusing especially since Windows comes with actual curl.

edit: I looked into this further and in powershell the stop-parsing token --% can be used but it still expands environment variables which cannot be escaped. It's more correct to say that type of escaping isn't possible, not that it doesn't "need" escaping. It does it's just not possible.

Escaping a % character as %%, the way you can do inside batch files, isn't supported.

So in a ps1 file I'm pretty sure it would look something like this:

&"c:\windows\system32\curl.exe" --% -v --write-out %{http_code} example.com

@jay jay closed this in bf68da3 Jan 26, 2023
@jay jay deleted the writeout_win32_batch branch January 26, 2023 23:51
jay added a commit to curl/curl that referenced this pull request Jan 26, 2023
- Clarify that in Windows batch files the % must be escaped as %%, and
  at the command prompt it cannot be escaped which could lead to
  incorrect expansion.

Prior to this change the doc implied % must be escaped as %% in win32
always.

---

Examples showing how a write-out argument is received by curl:

If curl --write-out "%{http_code}" is executed in a batch file:
{http_code}

If curl --write-out "%%{http_code}" is executed in a batch file:
%{http_code}

If curl --write-out "%{http_code}" is executed from the command prompt:
%{http_code}

If curl --write-out "%%{http_code}" is executed from the command prompt:
%%{http_code}

At the command prompt something like "%{speed_download}%{http_code}"
would first be parsed by the command interpreter as %{speed_download}%
and would be expanded as environment variable {speed_download} if it
existed, though that's highly unlikely since Windows environment names
don't use braces.

---

Reported-by: Muhammad Hussein Ammari

Ref: curl/everything-curl#279

Fixes #10323
Closes #10337
bch pushed a commit to bch/curl that referenced this pull request Jul 19, 2023
- Clarify that in Windows batch files the % must be escaped as %%, and
  at the command prompt it cannot be escaped which could lead to
  incorrect expansion.

Prior to this change the doc implied % must be escaped as %% in win32
always.

---

Examples showing how a write-out argument is received by curl:

If curl --write-out "%{http_code}" is executed in a batch file:
{http_code}

If curl --write-out "%%{http_code}" is executed in a batch file:
%{http_code}

If curl --write-out "%{http_code}" is executed from the command prompt:
%{http_code}

If curl --write-out "%%{http_code}" is executed from the command prompt:
%%{http_code}

At the command prompt something like "%{speed_download}%{http_code}"
would first be parsed by the command interpreter as %{speed_download}%
and would be expanded as environment variable {speed_download} if it
existed, though that's highly unlikely since Windows environment names
don't use braces.

---

Reported-by: Muhammad Hussein Ammari

Ref: curl/everything-curl#279

Fixes curl#10323
Closes curl#10337
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Formatted String
2 participants