-
Notifications
You must be signed in to change notification settings - Fork 8k
Treat -Target as literal in New-Item #25186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fix Path explain error
Fixed char '`' can not escape
Fixed wildcard conversion of hard links
Fix wildcard conversion of hard links
@microsoft-github-policy-service agree |
|
@GameMicrowave There is #16306 which must be fixed first since it is public API. |
| // if it is a wildcard char, escape it | ||
| // | ||
| if (IsWildcardChar(ch) && !charsNotToEscape.Contains(ch)) | ||
| if ((IsWildcardChar(ch) || ch == '`') && !charsNotToEscape.Contains(ch)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's discuss in related issue.
|
@GameMicrowave Please resolve merge conflicts. |
yes, i resolved it😊 |
|
@GameMicrowave I tried the build with examples from related issues and they don't work. Please add tests if you want to continue working on this issue. |
fix relative path issue
Add Test of file link creation
Alright, I've written a test script. In the process, I discovered another bug, which I've now fixed. |
|
|
||
| New-Item $hardLink -Target ([WildcardPattern]::Escape((Get-Item -PSPath $testFile))) -Type HardLink # create hardlink with absolute path | ||
| New-Item $symbolicLink -Target ([WildcardPattern]::Escape($testFile)) -Type SymbolicLink | ||
| New-Item $junction -Target ([WildcardPattern]::Escape((Get-Item -PSPath $testFolder))) -Type Junction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see PowerShell Committee conclusion in #6232 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I make the -Target and -Value parameters of New-Item treat the path as a literal.
make the `-target` treat the path as a literal
make the `-target` treat the path as a literal
improve test
Undo changes
| } | ||
| } | ||
|
|
||
| Describe "If the target path contains wildcard characters, the operation should succeed in creating a file link." -Tags @("CI", 'RequireAdminOnWindows') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All file link tests are in FileSystem.Tests.ps1 line 555. Please move new tests to the file.
| $symLinkToNothing = Join-Path $TestPath "sym-link-to-nowhere" | ||
| $dirSymLinkToDir = Join-Path $TestPath "symd-link-to-dir" | ||
| $junctionToDir = Join-Path $TestPath "junction-to-dir" | ||
| $hardLinkToFile = Join-Path $TestPath "[hard-to-file].txt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we haven't explicit tests please add new comment before the line that we intentionally use wildcard chars in follow names for testing.
if file name contains wildcard character,the new-item should succeed on creation file link
Add comment
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
📣 Hey @@GameMicrowave, how did we do? We would love to hear your feedback with the link below! 🗣️ 🔗 https://aka.ms/PSRepoFeedback |
|
@GameMicrowave Thanks for your contribution! |
PR Summary
Fix #6232
Fix #13136
Fix
New-Itemfails to create file links or creates links pointing to incorrect locations when the target path contains wildcard characters.Make the
-Targetand-Valueparameters ofNew-Itemtreat the path as a literal.PR Context
When using the
New-Itemcommand to create file links, if the target path contains wildcard characters, they are incorrectly interpreted. The following scenarios occur:Example:
Now, the path is correctly parsed to create the link.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.- [ ] Issue filed:
(which runs in a different PS Host).