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

Issue: Incorrect quote handling on PowerShell>=v7.3 when sudo'ing without {} #297

Open
gerardog opened this issue Sep 1, 2023 · 3 comments

Comments

@gerardog
Copy link
Owner

gerardog commented Sep 1, 2023

Issue Description

Creating this ticket for a future self to investigate and fix: https://stackoverflow.com/a/74440425/97471
See #295.

Looks like this quoting is required on Pwsh >= 7.3.0: https://github.com/gerardog/gsudo/blob/v2.4.0/src/gsudo/Helpers/CommandToRunAdapter.cs#L159

Steps to Reproduce

Screenshots

Context:

  • Windows version:
@LakeishaKowalczyk
Copy link

Hello, may I ask if it is possible to configure the shell or terminal so that they could automatically add curl braces for gsudo?

@gerardog
Copy link
Owner Author

gerardog commented Sep 8, 2023

It doesn't not work that way. When powershell finds the curly braces it parses it content as a scriptblock,, and encodes it in base64 before passing it to gsudo.

# without braces, gsudo gets the raw command. Quotes fidelity issues may ocurr
PS C:\> gsudo --debug echo $env:windir
Debug: Command Line: --debug echo C:\WINDOWS
(...)
C:\WINDOWS

# with braces, gsudo gets an encoded command. Quotes fidelity is preserved 
PS C:\> gsudo --debug { echo $env:windir }
Debug: Command Line: --debug -encodedCommand IABlAGMAaABvACAAJABlAG4AdgA6AHcAaQBuAGQAaQByACAA -inputFormat xml -outputFormat text
(...)
C:\WINDOWS

This mechanism was crafted so it's easy to call pwsh from within pwsh.

@LakeishaKowalczyk
Copy link

Thank you for your explanation. I wondered if it is possible to make powershell or terminal automatically convert the raw command into base64 when they execute gsudo by configuring them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants