Skip to content
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

Avoid a string allocation in IsUri #1680

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,9 @@ public static bool IsUri(this string input)
return false;
}

if (uri.IsFile && !input.StartsWith(Uri.UriSchemeFile + "://", StringComparison.OrdinalIgnoreCase))
{
return false;
}

return true;
return !uri.IsFile ||
// no need to check if input starts with {Uri.UriSchemeFile}:// because uri.IsFile ensures it is either '/' or `file://`
input.StartsWith(Uri.UriSchemeFile, StringComparison.OrdinalIgnoreCase);
}

[DebuggerStepThrough]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ public void IsUri_should_block_paths()
{
// especially on linux
// https://github.com/DuendeSoftware/Support/issues/148
" /path".IsUri().Should().BeFalse();
"/path".IsUri().Should().BeFalse();
" //".IsUri().Should().BeFalse();
"//".IsUri().Should().BeFalse();
"://".IsUri().Should().BeFalse();
" ://".IsUri().Should().BeFalse();
Expand Down