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 arguments parsing method of Invoke-ExternalCommand() #5839

Merged
merged 6 commits into from Mar 25, 2024

Conversation

niheaven
Copy link
Member

@niheaven niheaven commented Mar 21, 2024

Description

Final PR for stable version (#5424)

Before handling the argument list, it splits by finding spaces that are not in a path or before params (starting with / or -) and adding them to Process.StartInfo.ArgumentList or Process.StartInfo.Arguments.

Example: (https://regex101.com/r/HynlRG/1)

image

Motivation and Context

How Has This Been Tested?

Test with the following manifests, and scoop path with/without spaces.

msmpi
{
    "version": "10.1.1",
    "description": "Microsoft implementation of the Message Passing Interface standard for developing and running parallel applications on the Windows platform.",
    "homepage": "https://docs.microsoft.com/en-us/message-passing-interface/microsoft-mpi",
    "license": "MIT",
    "url": "https://github.com/Microsoft/Microsoft-MPI/releases/download/v10.1.1/msmpisetup.exe",
    "hash": "7308fd15e437d6829fd9c6ec5d801380faa3bff6e66e1dee3e8e005106fb6a68",
    "pre_install": "Invoke-ExternalCommand -Path \"$(Get-HelperPath -Helper 7zip)\" -ArgumentList @('x', \"-t# `\"$dir\\msmpisetup.exe`\" -o$dir\\tmp\") | Out-Null",
    "architecture": {
        "64bit": {
            "installer": {
                "script": [
                    "Expand-7zipArchive \"$dir\\tmp\\4.msi\" \"$dir\"",
                    "Remove-Item \"$dir\\msmpires.dll\"",
                    "Remove-Item \"$dir\\msmpi.dll\"",
                    "Rename-Item \"$dir\\msmpires64.dll\" \"$dir\\msmpires.dll\"",
                    "Rename-Item \"$dir\\msmpi64.dll\" \"$dir\\msmpi.dll\""
                ]
            }
        },
        "32bit": {
            "installer": {
                "script": "Expand-7zipArchive \"$dir\\tmp\\2.msi\" \"$dir\""
            }
        }
    },
    "post_install": [
        "Remove-Item -Recurse \"$dir\\tmp\"",
        "Remove-Item \"$dir\\msmpisetup.exe\""
    ],
    "env_add_path": ".",
    "checkver": {
        "github": "https://github.com/Microsoft/Microsoft-MPI"
    },
    "autoupdate": {
        "url": "https://github.com/Microsoft/Microsoft-MPI/releases/download/v$version/msmpisetup.exe"
    }
}
ida-free
{
    "version": "8.3",
    "description": "A multi-processor disassembler and debugger that offers so many features it is hard to describe them all",
    "homepage": "https://hex-rays.com/ida-free/",
    "license": "Freeware",
    "architecture": {
        "64bit": {
            "url": "https://out7.hex-rays.com/files/idafree83_windows.exe",
            "hash": "sha1:a63fe3107846ac60fd053c4312482f79d8ab179a"
        }
    },
    "pre_install": "if (!(is_admin)) { throw 'Administrator privileges are required' }",
    "installer": {
        "args": [
            "--mode unattended",
            "--prefix $dir"
        ]
    },
    "bin": "ida64.exe",
    "shortcuts": [
        [
            "ida64.exe",
            "IDA Freeware"
        ]
    ],
    "pre_uninstall": "if (!(is_admin)) { throw 'Administrator privileges are required' }",
    "uninstaller": {
        "file": "uninstall.exe",
        "args": [
            "--mode",
            "unattended"
        ]
    },
    "checkver": {
        "url": "https://hex-rays.com/ida-free/#download",
        "regex": "IDA\\sv([\\d.]+)\\s+"
    },
    "autoupdate": {
        "architecture": {
            "64bit": {
                "url": "https://out7.hex-rays.com/files/idafree$majorVersion$minorVersion_windows.exe",
                "hash": {
                    "url": "https://hex-rays.com/ida-free/#download",
                    "regex": "$sha1\\s+$basename"
                }
            }
        }
    }
}

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.

@chawyehsu
Copy link
Member

A patch addressing the critical #5065 finally! I'll take a serious review on it. I thought you'd address it in your work of #5124 but this one sounds better to me atm.

@niheaven
Copy link
Member Author

I initially planned to address it in #5124, but upon realizing that the PR was a refactoring, I decided to make it more manageable for review by separating the fix.

@chawyehsu
Copy link
Member

I have tested it with almost all manifests broken by #5065 , including cygwin (dash format args) and miniconda (slash format args), this patch works in both PS5 and PS7. Those two manifests are still problematic - cygwin shows GUI and miniconda won't install to directory having a dash symbol, but that's nothing wrong with this PR, args were parsed all correctly.

I don't see any existing app in offical buckets having an installer using args not starting with dash or slash. The regex is well crafted!

lib/core.ps1 Outdated Show resolved Hide resolved
lib/core.ps1 Outdated Show resolved Hide resolved
@chawyehsu chawyehsu changed the title fix(iec): Fix arguments parsing method of Invoke-ExternalCommand() fix(core): Fix arguments parsing method of Invoke-ExternalCommand() Mar 24, 2024
Copy link
Member

@chawyehsu chawyehsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any questions now, thank you for your work on this @niheaven.

Imo this is a critical part of the core therefore I suggest one more reviewer on this, but I don't know if any member is currently available. Please review when you are available. Good luck! /cc @ScoopInstaller/maintainers

@niheaven
Copy link
Member Author

I will merge this to develop after 24 hours for further testing. This seems to be the more appropriate approach.

@niheaven niheaven merged commit 77b66cc into develop Mar 25, 2024
2 checks passed
@niheaven niheaven deleted the fix-iec branch March 25, 2024 11:19
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

2 participants