Skip to content

(chocolatey-core.extension) regex pattern vs wildcard pattern usage in Get-AppInstallLocation #11

Description

@michaelray

(chocolatey-core.extension) The first parameter for the Get-AppInstallLocation function, $AppNamePattern, is documented/commented to be a "Regular expression pattern" and the function itself uses it as a regex pattern when using the -match operator in its body, BUT Get-AppInstallLocation also calls Get-UninstallRegistryKey, which does NOT use a regex pattern but instead a wildcard pattern. Regex patterns and wildcard patterns aren't interchangeable like that, however (ex. a regex pattern "Notepad\+\+.*" versus wildcard pattern "Notepad++*").

Expected Behavior

Since Get-AppInstallLocation takes a regular expression pattern (used with -match operator) as its parameter, it shouldn't use other functions or operators that treat that same parameter value as a wildcard pattern (used with -like operator). Get-UninstallRegistryKey (called by Get-AppInstallLocation) takes a wildcard pattern. Because of this interchangeable use, unexpected matches or lack of matches may occur when looking for the path. Errors occur ("ERROR: Bad argument to operator '-match': parsing "Notepad++*" - Nested quantifier +..") when passing in a wildcard pattern into Get-AppInstallLocation because of the use of -match (ex. "Notepad++*").

When passing a regex pattern into the Get-AppInstallLocation method, if a regex is pattern is provided, the calls -like operation used in Get-UninstallRegistryKey will be unexpectedly unmatched.

Possible Solution

Change Get-AppInstallLocation to not call any functions or operators that use wildcard pattern matching, since the parameter in this function is a regex pattern.

I would imagine this would mean maybe adjusting Get-UninstallRegistryKey to have an alternative parameter to pass in a regex pattern instead of a wildcard pattern, then have Get-AppInstallLocation call Get-UninstallRegistryKey with the new regex pattern parameter instead of the default (current) wildcard pattern. This would allow Get-UninstallRegistryKey to continue to function with existing calls while also supporting an alternative of using regex pattern matching instead of wildcard patterns so that other functions using wildcards could still use the same functions/logic.

Steps to Reproduce (for bugs)

  1. choco install notepadplusplus -y

I'm not sure what exactly is triggering the error I receive (see gist below), but when I attempt to install "notepadplusplus" (which installs "notepadplusplus.install"), I get a bad argument error due to a wildcard pattern being used. I discovered this issue in Get-AppInstallLocation in investigating that (chocolatey-community/chocolatey-packages#782 was submitted in regards to adjusting the notepadplusplus.install package as a seperate fix & PR chocolatey-community/chocolatey-packages#783 has also been submitted as a fix localized to the "notepadplusplus.install" package).

Context

This occurred when attempting to install the "notepadplusplus.install" package on a Windows 7 Pro 32 bit machine.

Your Environment

Related issue:
chocolatey-community/chocolatey-packages#782

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions