Skip to content

UriFormatter should use Uri.OriginalString when serializing #1105

@degant

Description

@degant

Bug description

Consider a Uri with default port (https://example.com:443/)

After a serialization/deserialization roundtrip, the resulting Uri.OriginalString doesn't contain the port anymore (https://example.com/). The messagepack UriFormatter should use Uri.OriginalString instead of Uri.ToString() to ensure lossless serialization?

Newtonsoft.Json and System.Text.Json both use Uri.OriginalString: dotnet/corefx#39015

Repro steps

var uri = new Uri("https://example.com:443/");

// Call Serialize/Deserialize, that's all.
byte[] bytes = MessagePackSerializer.Serialize(uri);
var uri2 = MessagePackSerializer.Deserialize<Uri>(bytes);

Console.WriteLine("Before: " + uri.OriginalString);
Console.WriteLine("After : " + uri2.OriginalString);
// Before: https://example.com:443/
// After : https://example.com/

Expected behavior

Resulting Uri.OriginalString should still be https://example.com:443/

Actual behavior

Resulting Uri.OriginalString is https://example.com/

  • Version used: 2.2.60
  • Runtime: .NET Framework 4.7.2

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions