Skip to content

Commit 1d717f8

Browse files
authored
URI comparison breaking change (#42829)
1 parent 369ea5d commit 1d717f8

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

docs/core/compatibility/8.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ If you're migrating an app to .NET 8, the breaking changes listed here might aff
115115
| Title | Type of change |
116116
| ------------------------------------------------------------------------------------------------- | ----------------- |
117117
| [SendFile throws NotSupportedException for connectionless sockets](networking/8.0/sendfile-connectionless.md) | Behavioral change |
118+
| [User info in `mailto:` URIs is compared](networking/8.0/uri-comparison.md) | Behavioral change |
118119

119120
## Reflection
120121

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
title: "Breaking change: User info in `mailto:` URIs is compared"
3+
description: Learn about the .NET 8 breaking change in networking where URI comparison now considers user info for `mailto:` URIs.
4+
ms.date: 10/03/2024
5+
---
6+
# User info in `mailto:` URIs is compared
7+
8+
Previously, <xref:System.Uri> didn't compare user info when comparing two `Uri` instances for equality. However, this behavior is not intuitive in the case of `mailto:` URIs. With this change, <xref:System.Uri.Equals*?displayProperty=nameWithType> and the [`==`](xref:System.Uri.op_Equality(System.Uri,System.Uri)) operator now consider user info when comparing URIs.
9+
10+
## Previous behavior
11+
12+
Prior to .NET 8, both of the following comparisons returned `true`.
13+
14+
```csharp
15+
Uri uri1 = new Uri("https://[email protected]");
16+
Uri uri2 = new Uri("https://[email protected]");
17+
System.Console.WriteLine(uri1 == uri2); // True.
18+
19+
Uri uri3 = new Uri("mailto:[email protected]");
20+
Uri uri4 = new Uri("mailto:[email protected]");
21+
System.Console.WriteLine(uri3 == uri4); // True.
22+
```
23+
24+
## New behavior
25+
26+
Starting in .NET 8, the first comparison still returns `true`, but the second comparison (of `mailto` URIs) returns `false`.
27+
28+
```csharp
29+
Uri uri1 = new Uri("https://[email protected]");
30+
Uri uri2 = new Uri("https://[email protected]");
31+
System.Console.WriteLine(uri1 == uri2); // True.
32+
33+
Uri uri3 = new Uri("mailto:[email protected]");
34+
Uri uri4 = new Uri("mailto:[email protected]");
35+
System.Console.WriteLine(uri3 == uri4); // False.
36+
```
37+
38+
## Version introduced
39+
40+
.NET 8
41+
42+
## Type of breaking change
43+
44+
This change is a [behavioral change](../../categories.md#behavioral-change).
45+
46+
## Reason for change
47+
48+
The previous behavior was unexpected and unintuitive.
49+
50+
## Recommended action
51+
52+
If you want to compare only the host part of email addresses, compare only the <xref:System.Uri.Host?displayProperty=nameWithType> members.
53+
54+
## Affected APIs
55+
56+
- <xref:System.Uri.Equals(System.Uri)?displayProperty=fullName>
57+
- <xref:System.Uri.Equals(System.Object)?displayProperty=fullName>
58+
- <xref:System.Uri.op_Equality(System.Uri,System.Uri)?displayProperty=fullName>

docs/core/compatibility/toc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ items:
238238
items:
239239
- name: SendFile throws NotSupportedException for connectionless sockets
240240
href: networking/8.0/sendfile-connectionless.md
241+
- name: User info in `mailto:` URIs is compared
242+
href: networking/8.0/uri-comparison.md
241243
- name: Reflection
242244
items:
243245
- name: IntPtr no longer used for function pointer types
@@ -1670,6 +1672,8 @@ items:
16701672
items:
16711673
- name: SendFile throws NotSupportedException for connectionless sockets
16721674
href: networking/8.0/sendfile-connectionless.md
1675+
- name: User info in `mailto:` URIs is compared
1676+
href: networking/8.0/uri-comparison.md
16731677
- name: .NET 7
16741678
items:
16751679
- name: AllowRenegotiation default is false

0 commit comments

Comments
 (0)