Skip to content

Make PowerShell slash-agnostic on Linux - #1081

Merged
Andy Jordan (andyleejordan) merged 8 commits into
masterfrom
andschwa/slash-agnostic
Jun 15, 2016
Merged

Make PowerShell slash-agnostic on Linux#1081
Andy Jordan (andyleejordan) merged 8 commits into
masterfrom
andschwa/slash-agnostic

Conversation

@andyleejordan

Copy link
Copy Markdown
Member

Resolves #570.

PowerShell cmdlets now accept both '/' and '' as directory separators on Linux.

This is work in progress as now I need to get escaping of backslashes to work correctly.

@andyleejordan Andy Jordan (andyleejordan) added this to the v0.5.0 milestone Jun 8, 2016
@andyleejordan Andy Jordan (andyleejordan) changed the title Andschwa/slash agnostic Make PowerShell slash-agnostic on Linux Jun 8, 2016

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

just to be over the top, i expect the following tests should be done as follows:

It "Should work with backslashes for each separator" {
   $testPath = "$TestDrive\testFile.txt".Replace("/","\")
   Get-Content $testPath | should be $data
}

It "Should work with backslashes for each separator" {
   $testPath = "$TestDrive/testFile.txt".Replace("\","/")
   Get-Content $testPath | should be $data
}
It "should work even if there are too many slashes" {
   $testPath = "$TestDrive//////testFile.txt"
   Get-Content $testPath | should be $data
}
It "should work even if there are too many backslashes" {
   $testPath = "$TestDrive\\\\\\\testFile.txt"
   Get-Content $testPath | should be $data
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Why does a lot of slashes work?

@vors

sergei (vors) commented Jun 10, 2016

Copy link
Copy Markdown
Collaborator

Does this change include escaping to allow use "foo\bar" as a file-name on Linux as foo\bar` ?

@andyleejordan

Copy link
Copy Markdown
Member Author

sergei (@vors)

This is work in progress as now I need to get escaping of backslashes to work correctly.

@vors

Copy link
Copy Markdown
Collaborator

LGTM, Jason Shirk (@lzybkr) can you take a look?

@andyleejordan

Copy link
Copy Markdown
Member Author

This branch has more WIP, stripping out normalization and handling it explicitly for escaped backslashes. Major WIP but any pointers would welcome, it's gonna be tricky.

@andyleejordan

Copy link
Copy Markdown
Member Author

James Truher (@JamesWTruher) I think we need to sit-down and design how we're going to handle the escaping. There are a few options.

@andyleejordan
Andy Jordan (andyleejordan) force-pushed the andschwa/slash-agnostic branch 2 times, most recently from e141096 to 0232f16 Compare June 15, 2016 19:16
Because normalization of paths occurs through the location globber and
filesystem provider by way of `path.Replace(alternate, default)`,
changing the alternate path separator on Linux to be '\' instead of
.NET's '/' let's PowerShell be "slash agnostic."
Assuming the path may not be normalized, to make PowerShell slash
agnostic in a filesystem whose "drive" is a '/' and a 'C:\', we need to
compare to both '/' and '\' for users of PowerShell's alternate path
separator on Linux ('\').
Reverted to original code and fixed correctly.
Reverted to original code and fixed correctly.
These comparisons did not need to be changed as the input path is not
modified. The normalized relate path created from the stack (if this
code path is taken) is created with the correct path separators.
@andyleejordan

Copy link
Copy Markdown
Member Author

sergei (@vors) I added the known issue for the current behavior. Do you sign-off?

@vors

Copy link
Copy Markdown
Collaborator

Andy Jordan (@andschwa) yes, sign off

@andyleejordan
Andy Jordan (andyleejordan) deleted the andschwa/slash-agnostic branch June 15, 2016 19:55
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj/PowerShell that referenced this pull request Aug 6, 2026
…ostic

Make PowerShell slash-agnostic on Linux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants