Skip to content

Bug: can not handle "/" correctly when reading registry item #5536

Open

Description

@ZSkycat

Steps to reproduce

# ** careful "\" and "/" **
# initialization
New-Item 'registry::HKEY_CURRENT_USER/test'
New-ItemProperty 'registry::HKEY_CURRENT_USER\test' -Name test1 -Value test1

# read item.
Get-Item 'registry::HKEY_CURRENT_USER/test'
Set-ItemProperty 'registry::HKEY_CURRENT_USER/test' -Name test2 -Value abcde

# read and create item
Copy-Item 'registry::HKEY_CURRENT_USER/test' 'registry::HKEY_CURRENT_USER/test/t1'
Copy-Item 'registry::HKEY_CURRENT_USER\test' 'registry::HKEY_CURRENT_USER/test/t1'

# clear
Remove-Item 'registry::HKEY_CURRENT_USER\test' -Recurse -Force

Expected behavior

no errors

Actual behavior

Get-Item : Cannot find path 'HKEY_CURRENT_USER/test' because it does not exist.
At line:1 char:1
+ Get-Item 'registry::HKEY_CURRENT_USER/test'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (HKEY_CURRENT_USER/test:String) [Get-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand

Set-ItemProperty : Cannot find path 'HKEY_CURRENT_USER/test' because it does not exist.
At line:1 char:1
+ Set-ItemProperty 'registry::HKEY_CURRENT_USER/test' -Name test2 -Valu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (HKEY_CURRENT_USER/test:String) [Set-ItemProperty], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetItemPropertyCommand

Copy-Item : Cannot find path 'HKEY_CURRENT_USER/test' because it does not exist.
At line:1 char:1
+ Copy-Item 'registry::HKEY_CURRENT_USER/test' 'registry::HKEY_CURRENT_ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (HKEY_CURRENT_USER/test:String) [Copy-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0-rc
PSEdition                      Core
GitCommitId                    v6.0.0-rc
OS                             Microsoft Windows 10.0.16299
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Summary

after trying, I found the law.

  1. can handle "/" correctly when creating item.
  2. can not handle "/" correctly when reading item.

related cmdlets

New-Item
New-ItemPropert
Get-ChildItem
Get-Item
Get-ItemProperty
Get-ItemPropertyValue
Set-Item
Set-ItemProperty
Clear-Item
Clear-ItemProperty
Remove-Item
Remove-ItemProperty
Rename-Itemre
Rename-ItemProperty
Copy-Item
Copy-ItemProperty
Move-Item
Move-ItemProperty

Activity

  1. ZSkycat commented on Nov 24, 2017

    @ZSkycat
    Author

    This bug also exists in Windows PowerShell (no core)

  2. iSazonov commented on Nov 24, 2017

    @iSazonov
    Collaborator

    '/' is allowed in registry key names. Can you to try escape '/'?

  3. added
    WG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.
    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif
    on Nov 24, 2017
  4. ZSkycat commented on Nov 24, 2017

    @ZSkycat
    Author

    Ilya (@iSazonov)
    I am using \ to avoid this bug.

    but I like automatic processing slash in powershell. (like file path)

  5. mklement0 commented on Nov 25, 2017

    @mklement0
    Contributor

    To be clear: The real bug is that / is supported at all as a path separator by the registry provider (even though the desire to use / and \ interchangeably, as with the file-system provider, is understandable).

    As Ilya (@iSazonov) points out, / is a valid character in a registry key (or value) name; therefore, it cannot function as the path separator, which in the registry provider's case should only be \.

    (Unfortunately, the objects returned by Get-PSProvider have no property that indicates a provider's path separator(s).)

    Using one of your examples:

    That New-Item 'registry::HKEY_CURRENT_USER/test' succeeds and functions the same as New-Item 'registry::HKEY_CURRENT_USER\test' is a manifestation of the bug.

  6. ZSkycat commented on Nov 25, 2017

    @ZSkycat
    Author

    Michael Klement (@mklement0) I understand.

    item name allow use '/' is too bad

    😂😂😂

  7. iSazonov commented on Nov 25, 2017

    @iSazonov
    Collaborator

    (Unfortunately, the objects returned by Get-PSProvider have no property that indicates a provider's path separator(s).)

    That's why I'm more inclined to think that we need to optimize providers and use types instead of strings.

  8. mklement0 commented on Nov 25, 2017

    @mklement0
    Contributor

    Ilya (@iSazonov): What do you mean by using types instead of strings?

  9. iSazonov commented on Nov 25, 2017

    @iSazonov
    Collaborator

    Providers work with strings and do parsing its on every operation. This results in poor performance and problems like this.

  10. rjmholt commented on Mar 7, 2018

    @rjmholt
    Collaborator

    Tracing this, it looks like there has already been some consideration of this in the NavigationProvider base class here.

    The comment seems to indicate that unless both back and forwards slashes are used, we want to treat forward slashes as back slashes. That seems a bit strange to me, but looking for input.

  11. 16 remaining items

  12. added
    Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributors
    on Oct 14, 2019
  13. iSazonov commented on Oct 14, 2019

    @iSazonov
    Collaborator

    Steve Lee (@SteveL-MSFT) Taking in account #10215 (PowerShell crash) please weigh the issue.

  14. SteveL-MSFT commented on Oct 14, 2019

    @SteveL-MSFT
    Member

    Ilya (@iSazonov) since the recursion issue repros with 5.1, this is not a regression. It's also an unlikely user scenario and I haven't seen many reports of this. I would like to have this fixed, but I don't think it changes the priority.

  15. vanillaSprinkles commented on May 16, 2021

    @vanillaSprinkles

    @PowerShell/powershell-committee reviewed this and similar to #6833, path normalization should happen within the provider. If the registry provider is inappropriately normalizing the path, that is a bug that should be fixed.

    It absolutely is inappropriately normalizing the path and causes a few other problems, I realize now I should've posted to this thread a fix, but I believe result = path.Replace(StringLiterals.AlternatePathSeparator, StringLiterals.DefaultPathSeparator); is the culprit and would likely remove quite a few issues (issue above references the correct line number).

    The registry allows slashes / in key names, plain and simple. Take a look at the EdgeExtensions within and look at those beautiful key-names:
    HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppContainer\Storage\microsoft.microsoftedge_8wekyb3d8bbwe\EdgeExtensions\Configuration\EdgeExtensions\ConfigurationStore\Extensions

  16. Deadooshka commented on Jul 13, 2023

    @Deadooshka

    got almost a same bug. Create some registry key 'Some_key' and create a subkey named '/' (slash only). Run Get-ChildItem -LiteralPath 'Registry::Some_key' -Recurse. You will see eternal repeating.

  17. microsoft-github-policy-service commented on Jan 10, 2024

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.

    Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.

  18. added
    KeepOpenThe bot will ignore these and not auto-close
    and removed
    Resolution-No ActivityIssue has had no activity for 6 months or more
    on Dec 3, 2024
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

    Committee-ReviewedPS-Committee has reviewed this and made a decisionIssue-BugIssue has been identified as a bug in the productKeepOpenThe bot will ignore these and not auto-closeUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issuesWG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions