gerardog/gsudo

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

gerardog opened this issue · 3 comments

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:

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

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.

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