fix(env): Avoid automatic expansion of %% in env (#5395)

Co-authored-by: Rashil Gandhi <46838874+rashil2000@users.noreply.github.com>
This commit is contained in:
0x574859
2023-02-25 20:38:09 +08:00
committed by GitHub
parent c44e214743
commit 0a39de86e2
2 changed files with 25 additions and 5 deletions

View File

@@ -11,7 +11,8 @@
- **autoupdate:** Fix file hash extraction ([#5295](https://github.com/ScoopInstaller/Scoop/issues/5295)) - **autoupdate:** Fix file hash extraction ([#5295](https://github.com/ScoopInstaller/Scoop/issues/5295))
- **shortcuts:** Output correctly formatted path ([#5333](https://github.com/ScoopInstaller/Scoop/issues/5333)) - **shortcuts:** Output correctly formatted path ([#5333](https://github.com/ScoopInstaller/Scoop/issues/5333))
- **core:** Fix `is_in_dir` under Unix ([#5391](https://github.com/ScoopInstaller/Scoop/issues/5391)) - **core:** Fix `is_in_dir` under Unix ([#5391](https://github.com/ScoopInstaller/Scoop/issues/5391))
- **install:** Fix download from private GitHub repositories ([#5357](https://github.com/ScoopInstaller/Scoop/issues/5357)) - **env:** Avoid automatic expansion of `%%` in env ([#5395](https://github.com/ScoopInstaller/Scoop/issues/5395))
- **install:** Fix download from private GitHub repositories ([#5361](https://github.com/ScoopInstaller/Scoop/issues/5361))
### Code Refactoring ### Code Refactoring

View File

@@ -662,10 +662,29 @@ function Invoke-ExternalCommand {
return $true return $true
} }
function env($name,$global,$val='__get') { function env($name, $global, $val = '__get') {
$target = 'User'; if($global) {$target = 'Machine'} $RegisterKey = if ($global) {
if($val -eq '__get') { [environment]::getEnvironmentVariable($name,$target) } Get-Item -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager'
else { [environment]::setEnvironmentVariable($name,$val,$target) } } else {
Get-Item -Path 'HKCU:'
}
$EnvRegisterKey = $RegisterKey.OpenSubKey('Environment', $val -ne '__get')
if ($val -eq '__get') {
$RegistryValueOption = [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames
$EnvRegisterKey.GetValue($name, $null, $RegistryValueOption)
} elseif ($val -eq $null) {
$EnvRegisterKey.DeleteValue($name)
} else {
$RegistryValueKind = if ($val.Contains('%')) {
[Microsoft.Win32.RegistryValueKind]::ExpandString
} elseif ($EnvRegisterKey.GetValue($name)) {
$EnvRegisterKey.GetValueKind($name)
} else {
[Microsoft.Win32.RegistryValueKind]::String
}
$EnvRegisterKey.SetValue($name, $val, $RegistryValueKind)
}
} }
function isFileLocked([string]$path) { function isFileLocked([string]$path) {