GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — enable support of folders and files with colon in name on Unix by SteveL-MSFT · Pull Request #4959 · PowerShell/PowerShell

Conversation

@SteveL-MSFT

@SteveL-MSFT Steve Lee (SteveL-MSFT) commented Sep 30, 2017

Copy link
Copy Markdown
Member

allow colons if it shows up after a path separator

fix #4889

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@SteveL-MSFT Steve Lee (SteveL-MSFT) assigned Mike Richmond (mirichmo) Sep 30, 2017
@SteveL-MSFT
Steve Lee (SteveL-MSFT) requested review from Aditya Patwardhan (adityapatwardhan) and Andrew (anmenaga) September 30, 2017 04:20
@SteveL-MSFT
Steve Lee (SteveL-MSFT) requested a review from Bruce Payette (BrucePay) as a code owner September 30, 2017 04:20
lzybkr
Jason Shirk (lzybkr) reviewed Sep 30, 2017
View reviewed changes
Comment thread src/System.Management.Automation/namespaces/LocationGlobber.cs Outdated

@lzybkr Jason Shirk (lzybkr) Sep 30, 2017

Copy link
Copy Markdown
Contributor

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.

This is inefficient to do unconditionally for an uncommon case, but it also doesn't fully fix the problem. Is it not possible to check if it looks like a drive, and if not, then it moist be a file? There are downsides to that approach though, so if it was rejected, I think it's worth noting why in the code.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@SteveL-MSFT Steve Lee (SteveL-MSFT) Sep 30, 2017

Copy link
Copy Markdown
Member Author

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.

The problem with the current code is that it always checks for the colon you see above and if it's there, it assumes it's a drive. What I'm doing here is what you are saying. If the colon is after a path separator, it doesn't look like a drive. If you mean to see if the left of the colon is a drive, wouldn't that be a bigger perf hit? I could certainly only look for the separator only if there is a colon.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@SteveL-MSFT Steve Lee (SteveL-MSFT) Sep 30, 2017

Copy link
Copy Markdown
Member Author

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.

With this change this still won't work:

1+1 > foo:bar.txt

instead you have to do:

1+1 > ./foo:bar.txt

Which seems fine to me

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lzybkr Jason Shirk (lzybkr) Oct 3, 2017

Copy link
Copy Markdown
Contributor

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.

At a minimum, yes, only look for the separator if there is a colon.

But the inconsistency of requiring a separator only if there is a colon - that seems silly and not easy to discover.

I guess I was suggesting to assume it's a drive (maybe not if there is a separator) because we're doing that already, and if it's not a drive, then don't error out, treat it as a filesystem path.

Of course this does introduce an ambiguity:

Set-Content -Path env:abc -Value 123

This sets the environment variable, not the file content. In cases like this, you'd have to use a separator. This example might seem not interesting, but something like this is more problematic:

Set-Content -Path "${prefix}:${suffix}" -Value 123

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@SteveL-MSFT Steve Lee (SteveL-MSFT) Oct 3, 2017

Copy link
Copy Markdown
Member Author

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.

Personally, I like having the distinction between a drive and a file with the separator.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@SteveL-MSFT
Steve Lee (SteveL-MSFT) force-pushed the colon-path branch from 92b947a to 6394373 Compare September 30, 2017 15:08
@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Sep 30, 2017

Copy link
Copy Markdown
Member Author

CI failures due to #4958

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT
Steve Lee (SteveL-MSFT) force-pushed the colon-path branch from 6394373 to 5a62062 Compare October 1, 2017 04:06
Steve Lee (SteveL-MSFT) added 2 commits September 30, 2017 21:06
@SteveL-MSFT
[feature]
8fa7127
support folders and files with colon in name
@SteveL-MSFT
[feature]
5a62062
only check separator in relation to colon if a colon is found
@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Oct 3, 2017

Copy link
Copy Markdown
Member Author

Jason Shirk (@lzybkr) are you ok with the current changes? would like to get it in for beta.8 if possible

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mirichmo
Mike Richmond (mirichmo) suggested changes Oct 4, 2017
View reviewed changes
Comment thread src/System.Management.Automation/namespaces/LocationGlobber.cs Outdated
// We must have a drive specified

result = true;
int separator = path.IndexOf(StringLiterals.DefaultPathSeparator, 0, index);

@mirichmo Mike Richmond (mirichmo) Oct 4, 2017

Copy link
Copy Markdown
Member

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.

Based on the documentation this does not look correct to me. It searches the string starting from the beginning though index count of characters for the matching separator. "C:\something.txt" Will always fail because the separator never matches the first character of the string ("C").

I think you might need:

separator = path.IndexOf(StringLiterals.AlternatePathSeparator, index, 1); 

This checks the character immediately after the index. But if you are going to do that, you might as well directly test index+1.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@SteveL-MSFT Steve Lee (SteveL-MSFT) Oct 4, 2017

Copy link
Copy Markdown
Member Author

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.

index points to location of the colon. So this test is to determine if there is a path separator between the beginning and the colon. So it should match ./foo:bar but not match foo:bar where the former is a file/directory and the latter is a drive path. One optimization I can see is I only need to search up to index-1 since I already know there is a colon at index.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Steve Lee (SteveL-MSFT) added 2 commits October 3, 2017 18:34
@SteveL-MSFT
[feature]
a860011
added comment to clarify algorithm
@SteveL-MSFT
added more tests
000a29c
@SteveL-MSFT
Steve Lee (SteveL-MSFT) force-pushed the colon-path branch from 3a062d8 to 000a29c Compare October 4, 2017 16:05
@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Oct 6, 2017

Copy link
Copy Markdown
Member Author

Mike Richmond (@mirichmo) can you review again?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mirichmo
Mike Richmond (mirichmo) approved these changes Oct 6, 2017
View reviewed changes
@mirichmo
Mike Richmond (mirichmo) merged commit 50607b9 into PowerShell:master Oct 6, 2017
@SteveL-MSFT
Steve Lee (SteveL-MSFT) deleted the colon-path branch November 12, 2017 05:17
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@SteveL-MSFT @mirichmo
Enable support of folders and files with colon in name on Unix (Power…
260a56b
…Shell#4959)

* [feature]
support folders and files with colon in name

* [feature]
only check separator in relation to colon if a colon is found

* [feature]
added comment to clarify algorithm

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

Reviewers

@anmenaga Andrew (anmenaga) Awaiting requested review from anmenaga
@adityapatwardhan Aditya Patwardhan (adityapatwardhan) Awaiting requested review from adityapatwardhan
@BrucePay Bruce Payette (BrucePay) Awaiting requested review from BrucePay
2 more reviewers
@lzybkr Jason Shirk (lzybkr) lzybkr left review comments
@mirichmo Mike Richmond (mirichmo) mirichmo approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@mirichmo Mike Richmond (mirichmo)

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Linux: cd and find commands fail when a colon is in the directory or file name

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@SteveL-MSFT @lzybkr @mirichmo
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.