ScoopInstaller / Scoop

A command-line installer for Windows.
https://scoop.sh
Other
20.85k stars 1.39k forks source link

[Bug] Function `Update-ManifestProperty` rewrites fields in `autoupdate` if it is a PSCustomObject #5933

Closed amorphobia closed 3 months ago

amorphobia commented 4 months ago

Bug Report

Current Behavior

I'll use a sample manifest to illustrate the issue. I have modified sudo.json in main bucket as following:

{
    "version": "0.1", # modified
    "description": "An approximation of the Unix sudo command. Shows a UAC popup window unfortunately.",
    "homepage": "https://github.com/lukesampson/psutils",
    "license": "MIT",
    "url": "https://raw.githubusercontent.com/lukesampson/psutils/c7116ac143ca81f223e6091d0974f45ac241eb1d/sudo.ps1",
    "hash": "0d3cf564dc584ea98b213b4763228dee523c32388b1293e77eff70344d294aa8",
    "bin": "sudo.ps1",
    "env_set": {
        "SUDO_VERSION": "0.1" # added
    },
    "checkver": {
        "url": "https://github.com/lukesampson/psutils/commits/master/sudo.ps1.atom",
        "regex": "(?s)>(\\d+)-(\\d+)-(\\d+)T.*?/(?<sha>[0-9a-f]{40})",
        "replace": "0.${1}.${2}.${3}"
    },
    "autoupdate": {
        "url": "https://raw.githubusercontent.com/lukesampson/psutils/$matchSha/sudo.ps1",
        "env_set": {
            "SUDO_VERSION": "$version" # added
        }
    }
}

I have add env_set and autoupdate.env_set, as well as change the current version to 0.1. Then run

& "$env:SCOOP_HOME/bin/checkver.ps1" -Dir <bucket_dir> -Update sudo

As a result, SUDO_VERSION in both env_set and autoupdate.env_set were changed to 0.2020.01.26.

Expected Behavior

Only SUDO_VERSION under env_set will be updated, and the value under autoupdate.env_set should keep the substitution pattern.

Possible Solution

The assignment operation for PSCustomObject only passes by reference, a copy operation can fix it.

System details

Windows version: 10

OS architecture: 64bit

PowerShell version: 5.1.20348.2400

amorphobia commented 4 months ago

I will commit a change trying to fix it.