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

UriBuilder does not update the port number when scheme changes in Powershell 7 #40680

Open
heikkiri opened this issue Aug 11, 2020 · 4 comments

Comments

@heikkiri
Copy link

Description

In PS7 - the URI port does not reset the port to reflect change to scheme change.

Repro steps
$builder = New-Object UriBuilder
$builder.GetType().Assembly.FullName
System.Private.Uri, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
$builder.Host = "me.com"
$builder

Fragment :
Host : me.com
Password :
Path : /
Port : -1
Query :
Scheme : http
Uri : http://me.com/
UserName :

$builder.Scheme = [Uri]::UriSchemeHttps
$builder

Fragment :
Host : me.com
Password :
Path : /
Port : 80
Query :
Scheme : https
Uri : https://me.com:80/
UserName :

Expected behavior: The port should be 443 when scheme is assigned HTTPS
Actual Behavior: The port for HTTPS is reported as 80, and not 443.

Configuration

$PSVersionTable

Name Value


PSVersion 7.0.3
PSEdition Core
GitCommitId 7.0.3
OS Microsoft Windows 10.0.19041
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

Regression?

Other information

Does not repro in PS5.1

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Aug 11, 2020
@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost
Copy link

ghost commented Aug 14, 2020

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@MihaZupan MihaZupan added this to the Future milestone Aug 14, 2020
@MihaZupan MihaZupan removed the untriaged New issue has not been triaged by the area owner label Aug 14, 2020
@MihaZupan
Copy link
Member

Does not repro in PS5.1

Are you sure? This behavior is the same going back to Framework 2.0 (maybe even earlier).

@svick
Copy link
Contributor

svick commented Aug 14, 2020

@MihaZupan

Even so, I do think the behavior is very confusing, because it depends on the order in which you access properties.

For example, consider the following code:

var builder = new UriBuilder { Host = "me.com" };
Console.WriteLine(builder.Port);
Console.WriteLine(builder.Uri);
Console.WriteLine(builder.Port);

Its output is:

-1
http://me.com/
80

I definitely wouldn't expect that accessing the Uri property would change the value of Port.

Does the current behavior have to be kept for backwards compatibility? If not, I think it should be changed. If it does have to be kept, I think it should at least be clearly documented (the current documentation is fairly sparse).

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

No branches or pull requests

5 participants