|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | 3 | // See the LICENSE file in the project root for more information. |
4 | 4 |
|
5 | | -using System.Text; |
| 5 | +using System.Collections.Generic; |
6 | 6 | using System.Common.Tests; |
| 7 | +using System.Linq; |
| 8 | +using System.Text; |
7 | 9 |
|
8 | 10 | using Xunit; |
9 | 11 |
|
@@ -567,5 +569,33 @@ public void Iri_RelativeUriCreation_ShouldNotNormalize(string uriString) |
567 | 569 | Assert.True(Uri.TryCreate(baseIri, href, out hrefAbsolute)); |
568 | 570 | Assert.Equal("http://www.contoso.com/%C3%A8", hrefAbsolute.AbsoluteUri); |
569 | 571 | } |
| 572 | + |
| 573 | + public static IEnumerable<object[]> AllForbiddenDecompositions() => |
| 574 | + from host in new[] { "canada.c\u2100.microsoft.com", // Unicode U+2100 'Account Of' decomposes to 'a/c' |
| 575 | + "canada.c\u2488.microsoft.com", // Unicode U+2488 'Digit One Full Stop" decomposes to '1.' |
| 576 | + "canada.c\u2048.microsoft.com", // Unicode U+2048 'Question Exclamation Mark" decomposes to '?!' |
| 577 | + "canada.c\uD83C\uDD00.microsoft.com" } // Unicode U+2488 'Digit Zero Full Stop" decomposes to '0.' |
| 578 | + from scheme in new[] { "http", // Known scheme. |
| 579 | + "test" } // Unknown scheme. |
| 580 | + select new object[] { scheme, host }; |
| 581 | + |
| 582 | + [Theory] |
| 583 | + [MemberData(nameof(AllForbiddenDecompositions))] |
| 584 | + public void Iri_AllForbiddenDecompositions_IdnHostThrows(string scheme, string host) |
| 585 | + { |
| 586 | + Uri uri = new Uri(scheme + "://" + host); |
| 587 | + Assert.Throws<UriFormatException>(() => uri.IdnHost); |
| 588 | + } |
| 589 | + |
| 590 | + [Theory] |
| 591 | + [MemberData(nameof(AllForbiddenDecompositions))] |
| 592 | + public void Iri_AllForbiddenDecompositions_NonIdnPropertiesOk(string scheme, string host) |
| 593 | + { |
| 594 | + Uri uri = new Uri(scheme + "://" + host); |
| 595 | + Assert.Equal(host, uri.Host); |
| 596 | + Assert.Equal(host, uri.DnsSafeHost); |
| 597 | + Assert.Equal(host, uri.Authority); |
| 598 | + Assert.Equal(scheme + "://" + host + "/", uri.AbsoluteUri); |
| 599 | + } |
570 | 600 | } |
571 | 601 | } |
0 commit comments