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

Uri constructor cannot parse http://hostname:port/ when hostname is * or + #77464

Closed
chuacw opened this issue Aug 3, 2022 · 8 comments
Closed

Comments

@chuacw
Copy link

chuacw commented Aug 3, 2022

Description

  • The Uri constructor cannot parse http://hostname:port/ when hostname is * or +, ie, http://*:9999/ or http://+:9999 will cause an exception to be thrown.
            httpListener = new HttpListener(); 
            string url = "http://*:1234/"; 
            Uri uri = new Uri(url);  
            // do something here... then pass the url (not uri) to the httpListener 
            httpListener.Prefixes.Add(url); 

  • On the "new Uri(url)" line, the following exception occurred
    System.UriFormatException
    HResult=0x80131537
    Message=Invalid URI: The hostname could not be parsed.
    Source=System.Private.Uri
    StackTrace:
    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
    at System.Uri..ctor(String uriString)
    at HttpListenerSegments.Program..ctor() in K:\Development\CSharp\HttpListenerSegments\Program.cs:line 18
    at HttpListenerSegments.Program.Main(String[] args) in K:\Development\CSharp\HttpListenerSegments\Program.cs:line 79

  • The Uri constructor should parse * or + into the DnsSafeHost, Host and IdnHost properties/fields (and whatever fields that currently holds the hostname).

  • .NET Core 2.1

  • Windows 11

  • x64

@svick
Copy link
Contributor

svick commented Aug 3, 2022

As far as I can tell, those are not valid HTTP URIs, so I think it's correct that the Uri constructor rejects them. They are valid HttpListener URI prefixes, but that's not the same thing as URIs.

Why do you think the current behavior is incorrect?

@chuacw
Copy link
Author

chuacw commented Aug 3, 2022

I didn't say it's incorrect, I say it should parse it. While it's true that * and + are not valid in a URI, I need the Uri class to support parsing of this, so that I don't have to parse it on my own, or duplicate an entire class just to parse * and + into the host field.

@buyaa-n
Copy link
Contributor

buyaa-n commented Aug 4, 2022

Tagging the area experts @dotnet/ncl for proper response, please move to runtime if needed

@GrabYourPitchforks GrabYourPitchforks transferred this issue from dotnet/core Oct 26, 2022
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Oct 26, 2022
@ghost
Copy link

ghost commented Oct 26, 2022

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

Issue Details

Description

  • The Uri constructor cannot parse http://hostname:port/ when hostname is * or +, ie, http://*:9999/ or http://+:9999 will cause an exception to be thrown.
            httpListener = new HttpListener(); 
            string url = "http://*:1234/"; 
            Uri uri = new Uri(url);  
            // do something here... then pass the url (not uri) to the httpListener 
            httpListener.Prefixes.Add(url); 

  • On the "new Uri(url)" line, the following exception occurred
    System.UriFormatException
    HResult=0x80131537
    Message=Invalid URI: The hostname could not be parsed.
    Source=System.Private.Uri
    StackTrace:
    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
    at System.Uri..ctor(String uriString)
    at HttpListenerSegments.Program..ctor() in K:\Development\CSharp\HttpListenerSegments\Program.cs:line 18
    at HttpListenerSegments.Program.Main(String[] args) in K:\Development\CSharp\HttpListenerSegments\Program.cs:line 79

  • The Uri constructor should parse * or + into the DnsSafeHost, Host and IdnHost properties/fields (and whatever fields that currently holds the hostname).

  • .NET Core 2.1

  • Windows 11

  • x64

Author: chuacw
Assignees: -
Labels:

area-System.Net, untriaged, Team:Libraries

Milestone: -

@ghost
Copy link

ghost commented Oct 26, 2022

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

Issue Details

Description

  • The Uri constructor cannot parse http://hostname:port/ when hostname is * or +, ie, http://*:9999/ or http://+:9999 will cause an exception to be thrown.
            httpListener = new HttpListener(); 
            string url = "http://*:1234/"; 
            Uri uri = new Uri(url);  
            // do something here... then pass the url (not uri) to the httpListener 
            httpListener.Prefixes.Add(url); 

  • On the "new Uri(url)" line, the following exception occurred
    System.UriFormatException
    HResult=0x80131537
    Message=Invalid URI: The hostname could not be parsed.
    Source=System.Private.Uri
    StackTrace:
    at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
    at System.Uri..ctor(String uriString)
    at HttpListenerSegments.Program..ctor() in K:\Development\CSharp\HttpListenerSegments\Program.cs:line 18
    at HttpListenerSegments.Program.Main(String[] args) in K:\Development\CSharp\HttpListenerSegments\Program.cs:line 79

  • The Uri constructor should parse * or + into the DnsSafeHost, Host and IdnHost properties/fields (and whatever fields that currently holds the hostname).

  • .NET Core 2.1

  • Windows 11

  • x64

Author: chuacw
Assignees: -
Labels:

area-System.Net, untriaged, feature-request

Milestone: -

@GrabYourPitchforks
Copy link
Member

Feature request for System.Uri area owners.

@MihaZupan
Copy link
Member

We've seen similar requests to relax the hostname parsing restrictions in the past (#36595).

It is worth noting that RFC 3986 allows such hostnames under the reg-name syntax definition, it is System.Uri that chooses to use a stricter DNS-like validation for hostnames.

We would be open to relaxing these requirements if there is enough interest in this.
Please upvote the original issue/this comment to let us gauge community interest in this and prioritize accordingly.

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

Duplicate of #64707

@MihaZupan MihaZupan marked this as a duplicate of #64707 Aug 3, 2023
@karelz karelz modified the milestones: Future, 8.0.0 Aug 3, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Sep 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants