Skip to content

Address Set-Location/Get-Item Issue With ?/* Characters - #12294

Closed
Bryan Berns (NoMoreFood) wants to merge 4 commits into
PowerShell:masterfrom
NoMoreFood:setlocation_wildcard
Closed

Address Set-Location/Get-Item Issue With ?/* Characters#12294
Bryan Berns (NoMoreFood) wants to merge 4 commits into
PowerShell:masterfrom
NoMoreFood:setlocation_wildcard

Conversation

@NoMoreFood

@NoMoreFood Bryan Berns (NoMoreFood) commented Apr 10, 2020

Copy link
Copy Markdown
Contributor

PR Summary

  • Adjusted behavior of GetCorrectCasedPath() which attempts to search for the file on the file system in order to normalize its case. Since some file systems support wildcard-type characters (e.g. MacOS) in path names so these need to be skipped to avoid erroneous resolution.
  • Added tests to detect this behavior.

PR Context

This corrects the behavior where Set-Location fails to change directory or changes to an entirely different child directory when the target directory contains characters such as '*'. Similarly, Get-Item also returns errant information.

Resolves: #12299

PR Checklist

@NoMoreFood Bryan Berns (NoMoreFood) changed the title WIP: Address Set-Location Issue With ?/* Characters Address Set-Location/Get-Item Issue With ?/* Characters Apr 10, 2020
@NoMoreFood Bryan Berns (NoMoreFood) changed the title Address Set-Location/Get-Item Issue With ?/* Characters WIP: Address Set-Location/Get-Item Issue With ?/* Characters Apr 11, 2020
- Adjusted behavior of GetCorrectCasedPath() which attempts to search for the file on the file system in order to normalize its case. Since some file systems support wildcard characters in path names; processing needs to be skipped for these.
- Added tests to detect this behavior.
@NoMoreFood Bryan Berns (NoMoreFood) changed the title WIP: Address Set-Location/Get-Item Issue With ?/* Characters Address Set-Location/Get-Item Issue With ?/* Characters Apr 11, 2020
@TravisEz13 Travis Plunk (TravisEz13) added the Breaking-Change breaking change that may affect users label Apr 11, 2020

@TravisEz13 Travis Plunk (TravisEz13) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This look good. Thanks.

I've requested a coup of changes in the tests to make sure it doesn't regress things now or in the future.

Comment thread test/powershell/Modules/Microsoft.PowerShell.Management/Set-Location.Tests.ps1 Outdated
@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Apr 11, 2020
@TravisEz13 Travis Plunk (TravisEz13) added the Review - Committee The PR/Issue needs a review from the PowerShell Committee label Apr 11, 2020
@TravisEz13

Copy link
Copy Markdown
Member

@PowerShell/powershell-committee This is a breaking change. Please review. We made a similar change for matching commands. Where we prefer literal matches over wildcard matches.

@NoMoreFood

Copy link
Copy Markdown
Contributor Author

Travis Plunk (@TravisEz13) So I can categorize these correctly in the future, can you educate me as to why this would be considered a breaking change?

@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Apr 11, 2020
Comment thread src/System.Management.Automation/namespaces/FileSystemProvider.cs Outdated
@SteveL-MSFT

Copy link
Copy Markdown
Member

@PowerShell/powershell-committee agrees that the current behavior is broken where:

set-location -literalpath ?

must treat ? as a literal value and not a wildcard. We don't believe this is a breaking change that causes concern, however, we are concerned with the location of the code change in a helper that is used by many code paths which itself may introduce a regression somewhere else.

@SteveL-MSFT Steve Lee (SteveL-MSFT) added Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Apr 15, 2020
- Mark backslash test on MacOS / Linux as 'Pending' vice 'Skipped'.
- Use Utils.Separators.StarOrQuestion instead of hard-coded constants.
@TravisEz13

Copy link
Copy Markdown
Member

I'm not sure your change addressed the committee's concern about the location of the change.

@TravisEz13 Travis Plunk (TravisEz13) removed the Breaking-Change breaking change that may affect users label May 20, 2020
@NoMoreFood

Bryan Berns (NoMoreFood) commented May 21, 2020

Copy link
Copy Markdown
Contributor Author

Travis Plunk (@TravisEz13) Sorry, the day job has distracted me from following through on this and one other PR. I honestly thought the "location of the code change" comment was sort of meant to be rhetorical. The bug itself can be scoped to that helper function: In what scenario would I possibly pass a literal, existing directory path to GetCorrectCasedPath() and it would be acceptable to get back a reference to an existing different directory? The function exists solely to normalize case within a path --- it should NEVER be returning a path to a different file.

@ghost ghost added the Review - Needed The PR is being reviewed label May 28, 2020
@ghost

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Mainainer, Please provide feedback and/or mark it as Waiting on Author

@TravisEz13 Travis Plunk (TravisEz13) added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Review - Needed The PR is being reviewed labels May 28, 2020
@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jun 9, 2020
- Added failure test for a directory that contains wildcard characters.
Comment thread src/System.Management.Automation/namespaces/FileSystemProvider.cs
Comment thread test/powershell/Modules/Microsoft.PowerShell.Management/Set-Location.Tests.ps1 Outdated
Comment thread test/powershell/Modules/Microsoft.PowerShell.Management/Set-Location.Tests.ps1 Outdated
Comment thread src/System.Management.Automation/namespaces/FileSystemProvider.cs
@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jun 10, 2020
@ghost ghost added the Review - Needed The PR is being reviewed label Jun 17, 2020
@ghost

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Mainainer, Please provide feedback and/or mark it as Waiting on Author

@NoMoreFood

Bryan Berns (NoMoreFood) commented Jun 25, 2020

Copy link
Copy Markdown
Contributor Author

Is this ready for merge or are we still waiting for reviews? Travis Plunk (@TravisEz13)

@NoMoreFood Bryan Berns (NoMoreFood) left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I have resolved these.

@TravisEz13

Copy link
Copy Markdown
Member

Travis Plunk (@TravisEz13) Sorry, the day job has distracted me from following through on this and one other PR. I honestly thought the "location of the code change" comment was sort of meant to be rhetorical. The bug itself can be scoped to that helper function: In what scenario would I possibly pass a literal, existing directory path to GetCorrectCasedPath() and it would be acceptable to get back a reference to an existing different directory? The function exists solely to normalize case within a path --- it should NEVER be returning a path to a different file.

Here is the direct call:
https://sourcegraph.com/search?q=repo:powershell/powershell+GetCorrectCasedPath&patternType=literal

Then, NormalizePath is used in these places:
https://sourcegraph.com/search?q=repo:powershell/powershell+content:%22Microsoft.PowerShell.Commands%22+content:%22NormalizePath%28%22+lang:c%23++-file:%22src/System.Management.Automation/namespaces/RegistryProvider.cs%22&patternType=literal#1

We need to make sure we didn't break any of these calls.

@ghost ghost removed the Review - Needed The PR is being reviewed label Oct 27, 2020
@TravisEz13 Travis Plunk (TravisEz13) added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept WG-Engine-Providers built-in PowerShell providers such as FileSystem, Certificates, Registry, etc. labels Oct 27, 2020
@TravisEz13

Copy link
Copy Markdown
Member

I'll let the Provider working group review from here.

@iSazonov

Copy link
Copy Markdown
Collaborator

The GetCorrectCasedPath() is not in right place. This would only have to be used in Formatting System and completors.

@NoMoreFood

Copy link
Copy Markdown
Contributor Author

Travis Plunk (@TravisEz13) All of the non-file system paths you reference end up calling a base class version or provider-specific version of NormalizePath() so this change luckily does not affect them.

Ilya (@iSazonov) I think that might be splitting hairs to some degree. When somebody does a Set-Location to a specific path, do you want the resultant path at the prompt to be case-accurate or not? I think it might be hard to address all the "what if" sort of cases. Regardless, this PR was authored to address the "bug" within GetCorrectCasedPath() itself so I was hoping not to boil the ocean to get this committed. :-)

@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Nov 4, 2020
@ghost ghost added the Review - Needed The PR is being reviewed label Nov 11, 2020
@ghost

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@TravisEz13 Travis Plunk (TravisEz13) added Needs-Triage The issue is new and needs to be triaged by a work group. and removed Review - Needed The PR is being reviewed labels May 8, 2023
@ghost ghost added the Review - Needed The PR is being reviewed label May 16, 2023
@ghost

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Committee-Reviewed PS-Committee has reviewed this and made a decision Needs-Triage The issue is new and needs to be triaged by a work group. Review - Needed The PR is being reviewed WG-Engine-Providers built-in PowerShell providers such as FileSystem, Certificates, Registry, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set-Location & Get-Item -LiteralPath Inconsistent On Files/Dirs With ?/* Characters

4 participants