Skip to content

UriBuilder adds explicit port to Uri.OriginalString even if not present in original Uri #31123

@cmeeren

Description

@cmeeren

When passing a Uri to UriBuilder, the resulting builder.Uri has a different OriginalString. Specifically, the port has been added to OriginalString where it was not present originally.

open System
open System.Web

let uri = "http://example.com"
Uri(uri).OriginalString  // is "http://example.com"
UriBuilder(Uri(uri)).Uri.OriginalString  // is "http://example.com:80/"

This has implications e.g. for serialization of URIs. Newtonsoft.Json seems to use Uri.OriginalString when serializing URIs. This means that after having been through a UriBuilder (e.g. to add path segments), all my URIs come out with ports where they originally had none.

Note that a slash is also added.

This bug exists in at least .NET Core 3.0 and 2.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions