allow * to be used in registry path for remove-item #4866

Merged
merged 3 commits into from Sep 25, 2017

Conversation

Projects
None yet
4 participants
Owner

SteveL-MSFT commented Sep 19, 2017

Code is creating a DirectoryInfo instance to determine if the path is a directory or file, but it fails because * is not allowed, however, * is a valid character in a registry path. Fix is to catch this exception and ignore it. This means that using -literalpath with an asterisk and the filesystem provider will now return an error rather than returning quietly.

Fix #4704
Fix #4330

@SteveL-MSFT SteveL-MSFT requested a review from anmenaga Sep 19, 2017

@@ -3266,6 +3266,10 @@ protected override void ProcessRecord()
{
// not a directory
}
+ catch (System.ArgumentException)
@anmenaga

anmenaga Sep 19, 2017

Contributor

Maybe it is better to skip that altogether if provider is not FileSystem provider?
e.g.: resolvedPath.Provider.Name.Equals(FileSystemProvider.ProviderName, StringComparison.OrdinalIgnoreCase)

@anmenaga

anmenaga Sep 19, 2017

Contributor

... that section altogether ...

@anmenaga

anmenaga Sep 19, 2017

Contributor

... that "DirectoryInfo code section" section altogether ...

@adityapatwardhan

adityapatwardhan Sep 19, 2017

Member

I agree checking for the provider seems to be a better option.

@SteveL-MSFT

SteveL-MSFT Sep 20, 2017

Owner

will make the change

@@ -3266,6 +3266,10 @@ protected override void ProcessRecord()
{
// not a directory
}
+ catch (System.ArgumentException)
+ {
@anmenaga

anmenaga Sep 19, 2017

Contributor

Need to make sure that FileSystem paths continue to work as they were before this new catch handler; 2 tests:

  1. remove-item with -Path and filesystem path that contains *
  2. remove-item with -LiteralPath and filesystem path that contains *
@SteveL-MSFT

SteveL-MSFT Sep 20, 2017

Owner

Looks like there's tests for -Path, I'll add a test for -LiteralPath with *

@SteveL-MSFT

SteveL-MSFT Sep 20, 2017

Owner

Looks like the current code does nothing if you use a * with -literalpath:

remove-item -literalpath .\a*.xml

I'll fix it so it returns error when using -literalpath, but it's a breaking change

@@ -3266,6 +3266,10 @@ protected override void ProcessRecord()
{
// not a directory
}
+ catch (System.ArgumentException)
@anmenaga

anmenaga Sep 19, 2017

Contributor

Maybe it is better to skip that altogether if provider is not FileSystem provider?
e.g.: resolvedPath.Provider.Name.Equals(FileSystemProvider.ProviderName, StringComparison.OrdinalIgnoreCase)

@anmenaga

anmenaga Sep 19, 2017

Contributor

... that section altogether ...

@anmenaga

anmenaga Sep 19, 2017

Contributor

... that "DirectoryInfo code section" section altogether ...

@adityapatwardhan

adityapatwardhan Sep 19, 2017

Member

I agree checking for the provider seems to be a better option.

@SteveL-MSFT

SteveL-MSFT Sep 20, 2017

Owner

will make the change

+ try {
+ $tempPath = "HKCU:\_tmp"
+ $testPath = "$tempPath\*\sub"
+ New-Item -Force $testPath
@adityapatwardhan

adityapatwardhan Sep 19, 2017

Member

Please assign to null.

$null = New-Item -Force $testPath
+ $testPath | Should Not Exist
+ }
+ finally {
+ Remove-Item -Recurse $tempPath
@adityapatwardhan

adityapatwardhan Sep 19, 2017

Member

Please add -ErrorAction SilentlyContinue -Force

Owner

SteveL-MSFT commented Sep 20, 2017

@PowerShell/powershell-committee reviewed this and is ok with the minor breaking change

Member

adityapatwardhan commented Sep 22, 2017

@anmenaga Can you have a look again?

Member

adityapatwardhan commented Sep 22, 2017

@SteveL-MSFT Can you update the PR description.

SteveL-MSFT added some commits Sep 19, 2017

[feature]
allow * to be used in registry path for remove-item
[feature]
address PR feedback
have remove-item return error if -literalpath doesn't resolve to path

@SteveL-MSFT SteveL-MSFT reopened this Sep 23, 2017

[feature]
fix in navigation exposed an issue with WSMan Config Provider tests
that require -Recurse to be used otherwise a confirmation prompt shows
up

@adityapatwardhan adityapatwardhan merged commit 65415c3 into PowerShell:master Sep 25, 2017

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

powercode pushed a commit to powercode/PowerShell that referenced this pull request Oct 19, 2017

allow * to be used in registry path for remove-item (#4866)
* [feature]
allow * to be used in registry path for remove-item

* [feature]
address PR feedback
have remove-item return error if -literalpath doesn't resolve to path

* [feature]
fix in navigation exposed an issue with WSMan Config Provider tests
that require -Recurse to be used otherwise a confirmation prompt shows
up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment