Skip to content

bug: get-item registry slash-magic trim'ing incorrectly #15342

Closed

Description

Steps to reproduce

pre-setup:

  • registry keys:
    • HKEY_CURRENT_USER\test\noslashes
    • HKEY_CURRENT_USER\test\some/test/key/
    • HKEY_CURRENT_USER\test\another//caveat/
  • or as a file.reg:
    • Windows Registry Editor Version 5.00
      [HKEY_CURRENT_USER\test]
      [HKEY_CURRENT_USER\test\another//caveat/]
      [HKEY_CURRENT_USER\test\noslashes]
      [HKEY_CURRENT_USER\test\some/test/key/]
      
## should work (and works)
get-item HKCU:\test\noslashes


## should error (and it 'works' by triming slashes)
get-item HKCU:\test\noslashes//////


## should error (and it errors)
get-item HKCU:\test\some/test/key


## should work (and it shows broken behavior)
get-item HKCU:\test\some/test/key/


## should error (and it 'works' by triming slashes)
get-item HKCU:\test\some/test/key////


## should work (and it errors)
get-item HKCU:\test\another//caveat/

Expected behavior

PS HKCU:\> ## should work (and works)
PS HKCU:\> get-item HKCU:\test\noslashes

    Hive: HKEY_CURRENT_USER\test

Name                           Property
----                           --------
noslashes




PS HKCU:\> ## should error (and it 'works' by triming slashes)
PS HKCU:\> get-item HKCU:\test\noslashes//////
Get-Item: Cannot find path 'HKCU:\test\noslashes//////' because it does not exist.




PS HKCU:\> ## should error (and it errors)
PS HKCU:\> get-item HKCU:\test\some/test/key
Get-Item: Cannot find path 'HKCU:\test\some\test\key' because it does not exist.



PS HKCU:\> ## should work (and it shows broken behavior)
PS HKCU:\> get-item HKCU:\test\some/test/key/

    Hive: HKEY_CURRENT_USER\test

Name                           Property
----                           --------
some/test/key/




PS HKCU:\> ## should error (and it 'works' by triming slashes)
PS HKCU:\> get-item HKCU:\test\some/test/key////
Get-Item: Cannot find path 'HKCU:\test\some/test/key////' because it does not exist.




PS HKCU:\> ## should work (and it errors)
PS HKCU:\> get-item HKCU:\test\another//caveat/

    Hive: HKEY_CURRENT_USER\test

Name                           Property
----                           --------
another//caveat/

Actual behavior (ps 7.1.3)

PS HKCU:\> ## should work (and works)
PS HKCU:\> get-item HKCU:\test\noslashes

    Hive: HKEY_CURRENT_USER\test

Name                           Property
----                           --------
noslashes




PS HKCU:\> ## should error (and it 'works' by triming slashes)
PS HKCU:\> get-item HKCU:\test\noslashes//////

    Hive: HKEY_CURRENT_USER\test

Name                           Property
----                           --------
noslashes




PS HKCU:\> ## should error (and it errors)
PS HKCU:\> get-item HKCU:\test\some/test/key
Get-Item: Cannot find path 'HKCU:\test\some\test\key' because it does not exist.



PS HKCU:\> ## should work (and it shows broken behavior)
PS HKCU:\> get-item HKCU:\test\some/test/key/

    Hive: HKEY_CURRENT_USER\test

Name                           Property
----                           --------
key




PS HKCU:\> ## should error (and it 'works' by triming slashes)
PS HKCU:\> get-item HKCU:\test\some/test/key////

    Hive: HKEY_CURRENT_USER\test

Name                           Property
----                           --------
key




PS HKCU:\> ## should work (and it errors)
PS HKCU:\> get-item HKCU:\test\another//caveat/
Get-Item: Cannot find path 'HKCU:\test\another\caveat\' because it does not exist.

Environment data (ps 7.1.3)

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

potentially related

Activity

  1. added
    Needs-Triage
    on May 3, 2021
  2. added
    WG-Engine-Providers
    on May 4, 2021
  3. vanillaSprinkles commented on May 10, 2021

    @vanillaSprinkles
    Author

    somebody correct me if I'm wrong, but I believe the problem is here:

    • https://github.com/renehernandez/PowerShell/blob/master/src/System.Management.Automation/namespaces/RegistryProvider.cs#L2937
      • aka (in case master's line refs get clobbered):

            private string NormalizePath(string path)
            {
                string result = path;
        
                if (!string.IsNullOrEmpty(path))
                {
                    result = path.Replace(StringLiterals.AlternatePathSeparator, StringLiterals.DefaultPathSeparator);
        
                    // Remove relative path tokens
                    if (HasRelativePathTokens(path))
                    {
                        result = NormalizeRelativePath(result, null);
                    }
                }
        
                return result;
            }
        
      • line: result = path.Replace(StringLiterals.AlternatePathSeparator, StringLiterals.DefaultPathSeparator); should be removed. Registry key names include / - and I am guessing now that StringLiterals.AlternatePathSeparator is converting that character to \

    GitHub
    PowerShell for every system! Contribute to renehernandez/PowerShell development by creating an account on GitHub.
  4. rjmholt commented on May 25, 2021

    @rjmholt
    Collaborator

    As you've linked in the description, this is basically an extension (and thus possibly a duplicate for task-tracking purposes) of #5536.

    PowerShell provider path handling is done at a higher layer than the provider itself currently, meaning that there are registry paths that can't currently be represented in PowerShell.

    To solve this, we'd need to allow providers to handle their own path format in some way. We'd also need to evaluate the breaking change there, since users might be using / today with registry paths and would expect that to continue working as it does today.

  5. added
    Resolution-Duplicate
    and removed
    Needs-Triage
    on May 28, 2021
  6. daxian-dbw commented on May 28, 2021

    @daxian-dbw
    Member

    Resolve this issue as a duplicate of #5536

  7. ghost closed this as completedon May 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-DuplicateWG-Engine-Providers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions