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

fix(core): Fix "Invoke-ExternalCommand" quoting rules #5945

Merged
merged 6 commits into from
May 11, 2024
Merged

Conversation

niheaven
Copy link
Member

@niheaven niheaven commented May 8, 2024

Description

Quoting rules...

There's a bug in PS5 if extract_dir has spaces when using 7z to extract the archive, and this PR tries to fix it.

Motivation and Context

There's a known bug that NSIS's /D param doesn't work if the path has spaces in PS7, if we provide /D=xxx xxx in ArgumentList, the NSIS installer doesn't recognize it, don't know why.

How Has This Been Tested?

Local install affected apps in PS5 and add some test cases.

Checklist:

  • I have read the Contributing Guide.
  • I have ensured that I am targeting the develop branch.
  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.
  • I have added an entry in the CHANGELOG.

@niheaven niheaven requested a review from chawyehsu May 8, 2024 09:02
@chawyehsu
Copy link
Member

Could you please add unit tests for this type of situation to the Decompress testsuite?


The NSIS Document says that there are two constrains of the /D switch.

  • NO quotes (even if the path contains spaces)
  • It MUST be the last parameter used in the command line

There's a known bug that NSIS's /D param doesn't work if the path has spaces in PS7, if we provide /D=xxx xxx in ArgumentList, the NSIS installer doesn't recognize it, don't know why.

Probably the second constrain is the cause in this case?

lib/core.ps1 Show resolved Hide resolved
@niheaven
Copy link
Member Author

niheaven commented May 8, 2024

Alright, I will implement some test cases and refactor the decompression test structure accordingly.

NSIS in PS7:

image
image
image
image

@niheaven
Copy link
Member Author

niheaven commented May 8, 2024

Test cases added, all done.

@chawyehsu
Copy link
Member

I think I found out the cause of the /D switch getting ignored in PS7 @niheaven

image

$Process = New-Object System.Diagnostics.Process
$Process.StartInfo.FileName = '...exe'
$Process.StartInfo.ArgumentList.Add('/S')
$Process.StartInfo.ArgumentList.Add('/D=C:\temp\miniconda space space')

If an arguement that is added to ProcessStartInfo.ArgumentList contains whitespaces, it will be wrapped with quotes before being passed to the native command, this is an expected behavoir for most cases but not for the NSIS installer.

Probably we have to use the legacy argument escaping necessarily for NSIS installers, whether in PS5 or PS7, i.e. there needs to be one more condition of testing NSIS installers in

if ((-not $LegacyCommand) -and $SupportArgumentList) {

@chawyehsu
Copy link
Member

Regarding to the TestCases, perhaps there should also be test nsis installers to validate such a situation.

@niheaven
Copy link
Member Author

niheaven commented May 9, 2024

Probably we have to use the legacy argument escaping necessarily for NSIS installers

Indeed, that was my initial thought, but I was unable to find an efficient method to verify it. PEiD or Exeinfo should be able to accomplish the task, yet I was unable to discern their methodology. (Using a hex editor, I could find Nullsoft in PE, but couldn't with PS)

@chawyehsu
Copy link
Member

Reading hex to identify NSIS installers requires extra IO. What about picking the inactive #3502 up? That may take much work though, and a workaround (by just checking if /D=<path> exists?) should be released to mitigate existing issues.

@niheaven
Copy link
Member Author

niheaven commented May 9, 2024

I am currently addressing issue #3502 by dividing it into multiple individual PRs, with some already merged, the most recent being #5951. I will also review any existing manifest that utilizes /D=, as I recall that other installers may use this as well.

@niheaven
Copy link
Member Author

niheaven commented May 9, 2024

Check NSIS installer by its arguments (should have /S and /D=xxx), and add test cases.

@chawyehsu
Copy link
Member

Check NSIS installer by its arguments (should have /S and /D=xxx)

That's the workaround I was thinking of.

@niheaven niheaven merged commit 1752050 into develop May 11, 2024
2 checks passed
@niheaven niheaven deleted the fix-iec-quote branch May 11, 2024 06:49
@RaphaelTarita
Copy link

also closes ScoopInstaller/Extras#13160. When is this fix expected to be released?

@niheaven
Copy link
Member Author

In a few days.

@chawyehsu
Copy link
Member

chawyehsu commented May 13, 2024

I would like to cherry-pick this and publish a patch release instead of waiting for days. And I'm seeing the sqlite cache feature needs some more tweaks to be available for master channel. WDYT? @niheaven

@niheaven
Copy link
Member Author

Although I believe the SQLite cache feature is stable enough for the end user, cherry-picking some fixes to the main branch is a decision that requires careful consideration. I will proceed with it now and create a pull request.

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

Successfully merging this pull request may close these issues.

None yet

3 participants