Skip to content

[Bug] strip_path's parameter is not correctly passed to Split-PathLikeEnvVar #5936

@Capella87

Description

@Capella87

Bug Report

Current Behavior

One parameter was entered with a different name, so the following error occurs every time it is installed or uninstalled.

InvalidOperation: C:\Users\[redacted]\scoop\apps\scoop\current\lib\system.ps1:85
Line |
  85 |          $splitPattern = $Pattern.Split(';', [System.StringSplitOption|          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.

Since $Pattern is $null, it occurs error.

Expected Behavior

In sdl2 manifest, strip_path function has been invoked several times. For example, in the manifest's installer script:

"$null, $currpath = strip_path (env 'PKG_CONFIG_PATH' $global) $pcdir",
"env 'PKG_CONFIG_PATH' $global \"$pcdir;$currpath\"",

strip_path function requires two parameters, the returned variable from env and $pcdir respectively. And it utilizes the second returned one, $currpath and makes use of it to configure paths.
Since the function is a deprecated function, it actually outputs a warning and then another function, Split-PathLikeEnvVar is called. In the past, it was Test-PathLikeEnvVar and required two string variables, $Name and '$Path'.

In the recent commit, The string type $Name parameter has been updated to the string array type $Pattern. But strip_path still provides the parameter with the old name.
So, Split-PathLikeEnvVar wants $Pattern, but it has $null value, then the error occurs.

Additional context/output

I discovered this issue at sdl2 manifest which contains the problematic functions stored at ScoopInstaller/Extras. Here's the output:

PS> scoop update sdl2
Uninstalling 'sdl2' (2.30.2)
Running uninstaller script...
WARN  "env" will be deprecated. Please change your code/manifest to use "Get-EnvVar"
      -> :4:38
WARN  "strip_path" will be deprecated. Please change your code/manifest to use "Split-PathLikeEnvVar"
      -> :4:26
InvalidOperation: C:\Users\[redacted]\scoop\apps\scoop\current\lib\system.ps1:85
Line |
  85 |          $splitPattern = $Pattern.Split(';', [System.StringSplitOption|          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
WARN  "env" will be deprecated. Please change your code/manifest to use "Get-EnvVar"
      -> :9:38
WARN  "strip_path" will be deprecated. Please change your code/manifest to use "Split-PathLikeEnvVar"
      -> :9:26
InvalidOperation: C:\Users\[redacted]\scoop\apps\scoop\current\lib\system.ps1:85
Line |
  85 |          $splitPattern = $Pattern.Split(';', [System.StringSplitOption|          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
WARN  "strip_path" will be deprecated. Please change your code/manifest to use "Split-PathLikeEnvVar"
      -> :15:26
InvalidOperation: C:\Users\[redacted]\scoop\apps\scoop\current\lib\system.ps1:85
Line |
  85 |          $splitPattern = $Pattern.Split(';', [System.StringSplitOption|          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
WARN  "strip_path" will be deprecated. Please change your code/manifest to use "Split-PathLikeEnvVar"
      -> :17:26
InvalidOperation: C:\Users\[redacted]\scoop\apps\scoop\current\lib\system.ps1:85
Line |
  85 |          $splitPattern = $Pattern.Split(';', [System.StringSplitOption|          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
Unlinking ~\scoop\apps\sdl2\current
Installing 'sdl2' (2.30.3) [64bit] from 'extras' bucket
Loading SDL2-devel-2.30.3-VC.zip from cache.
Loading SDL2-2.30.3.zip from cache.
Extracting SDL2-devel-2.30.3-VC.zip ... done.
Extracting SDL2-2.30.3.zip ... done.
Running installer script...
WARN  "env" will be deprecated. Please change your code/manifest to use "Get-EnvVar"
      -> :33:32
WARN  "strip_path" will be deprecated. Please change your code/manifest to use "Split-PathLikeEnvVar"
      -> :33:20
InvalidOperation: C:\Users\[redacted]\scoop\apps\scoop\current\lib\system.ps1:85
Line |
  85 |          $splitPattern = $Pattern.Split(';', [System.StringSplitOption|          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
WARN  "env" will be deprecated. Please change your code/manifest to use "Set-EnvVar"
      -> :34:1
WARN  "env" will be deprecated. Please change your code/manifest to use "Get-EnvVar"
      -> :35:32
WARN  "strip_path" will be deprecated. Please change your code/manifest to use "Split-PathLikeEnvVar"
      -> :35:20
InvalidOperation: C:\Users\[redacted]\scoop\apps\scoop\current\lib\system.ps1:85
Line |
  85 |          $splitPattern = $Pattern.Split(';', [System.StringSplitOption|          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
WARN  "env" will be deprecated. Please change your code/manifest to use "Set-EnvVar"
      -> :36:1
WARN  "strip_path" will be deprecated. Please change your code/manifest to use "Split-PathLikeEnvVar"
      -> :38:31
InvalidOperation: C:\Users\[redacted]\scoop\apps\scoop\current\lib\system.ps1:85
Line |
  85 |          $splitPattern = $Pattern.Split(';', [System.StringSplitOption|          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
WARN  "strip_path" will be deprecated. Please change your code/manifest to use "Split-PathLikeEnvVar"
      -> :40:33
InvalidOperation: C:\Users\[redacted]\scoop\apps\scoop\current\lib\system.ps1:85
Line |
  85 |          $splitPattern = $Pattern.Split(';', [System.StringSplitOption|          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
Linking ~\scoop\apps\sdl2\current => ~\scoop\apps\sdl2\2.30.3
'sdl2' (2.30.3) was installed successfully!

Possible Solution

This problem can be resolved with 2 ways. We should update strip_path function in lib/system.ps1 to provide the parameter with -Pattern. Also, Split-PathLikeEnvVar now receives the changed one as a string array, it would be better to include casting to array before invoking the function.

strip_path is a deprecated function, so manifests that uses it should be updated not to use that function.

System details

Windows version: Windows 10 22H2, and Windows 11 23H2 (Tested on both environments)

OS architecture: AMD64 (x64)

PowerShell version: [output of "$($PSVersionTable.PSVersion)"]

PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.2
PSEdition                      Core
GitCommitId                    7.4.2
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Additional software:
None

Scoop Configuration

{
  "last_update": "2024-05-02T11:52:06.2956348+09:00",
  "debug": true,
  "aria2-enabled": true,
  "aria2-warning-enabled": false,
  "use_external_7zip": true,
  "scoop_branch": "master",
  "scoop_repo": "https://github.com/ScoopInstaller/Scoop"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions