public void IdnCheckHostName_UnicodeIdnOffIriOn_Dns() { using (var helper = new ThreadCultureChange()) { Assert.Equal(UriHostNameType.Dns, Uri.CheckHostName("nZMot\u00E1\u00D3\u0063vKi\u00CD.contoso.com")); helper.ChangeCultureInfo("zh-cn"); Assert.Equal(UriHostNameType.Dns, Uri.CheckHostName("nZMot\u00E1\u00D3\u0063vKi\u00CD.contoso.com")); } }
public void UriEscapingDataString_UnicodeWithIRI_Escaped() { using (var iriHelper = new ThreadCultureChange()) { string input = "\u30AF"; string output = Uri.EscapeDataString(input); Assert.Equal("%E3%82%AF", output); iriHelper.ChangeCultureInfo("zh-cn"); string outputZhCn = Uri.EscapeDataString(input); Assert.Equal(output, outputZhCn); //, "Same normalized result expected in different locales." } }
public void UriEscapingDataString_Unicode_SurrogatePair() { using (ThreadCultureChange iriHelper = new ThreadCultureChange()) { string output = Uri.EscapeDataString(GB18030CertificationString1); Assert.Equal( @"%E6%95%B0%E6%8D%AE%20eq" + "%20%27%F0%A0%80%80%F0%A0%80%81%F0%A0%80%82%F0%A0%80%83%F0%AA%9B%91" + "%F0%AA%9B%92%F0%AA%9B%93%F0%AA%9B%94%F0%AA%9B%95%F0%AA%9B%96%27", output); iriHelper.ChangeCultureInfo("zh-cn"); string outputZhCn = Uri.EscapeDataString(GB18030CertificationString1); Assert.Equal(output, outputZhCn); //"Same normalized result expected in different locales." } }
public void UriUnescapeInvalid_ValidUtf8IncompleteUtf8AsciiIriOn_InvalidUtf8LeftAlone() { using (ThreadCultureChange irihelper = new ThreadCultureChange()) { string input = "http://host/%E6%9C%88%E6%9C%59"; Uri uri = new Uri(input); Assert.Equal("http://host/%E6%9C%88%E6%9CY", uri.AbsoluteUri); Assert.Equal("http://host/\u6708%E6%9CY", uri.ToString()); string output = Uri.UnescapeDataString(input); Assert.Equal("http://host/\u6708%E6%9CY", output); irihelper.ChangeCultureInfo("zh-cn"); Uri uriZhCn = new Uri(input); Assert.Equal(uri.ToString(), uriZhCn.ToString()); Assert.Equal(uri.AbsoluteUri, uriZhCn.AbsoluteUri); string outputZhCn = Uri.UnescapeDataString(input); Assert.Equal(output, outputZhCn); } }
public void UriUnescape_AsciiUtf8AsciiIriOn_ValidUnescaped() { using (ThreadCultureChange irihelper = new ThreadCultureChange()) { string input = "http://host/%5A%E6%9C%88%5A"; string output = Uri.UnescapeDataString(input); Assert.Equal("http://host/Z\u6708Z", output); Uri uri = new Uri(input); Assert.Equal("http://host/Z%E6%9C%88Z", uri.AbsoluteUri); irihelper.ChangeCultureInfo("zh-cn"); string outputZhCn = Uri.UnescapeDataString(input); Assert.Equal(output, outputZhCn); Uri uriZhCn = new Uri(input); Assert.Equal(uri.AbsoluteUri, uriZhCn.AbsoluteUri); } }
public void UriAbsoluteEscaping_SurrogatePair_LocaleIndependent() { string uriString = "http://contosotest.conto.soco.ntosoco.com/surrgtest()?$filter="; string expectedString = uriString + "%E6%95%B0%E6%8D%AE%20eq%20" + "'%F0%A0%80%80%F0%A0%80%81%F0%A0%80%82%F0%A0%80%83%F0%AA%9B%91%F0%AA%9B" + "%92%F0%AA%9B%93%F0%AA%9B%94%F0%AA%9B%95%F0%AA%9B%96'"; using (ThreadCultureChange iriHelper = new ThreadCultureChange()) { Uri uri = new Uri(uriString + Uri.EscapeDataString(GB18030CertificationString1)); Assert.Equal(expectedString, uri.AbsoluteUri); iriHelper.ChangeCultureInfo("zh-cn"); Uri uriZhCn = new Uri(uriString + Uri.EscapeDataString(GB18030CertificationString1)); Assert.Equal(uri.AbsoluteUri, uriZhCn.AbsoluteUri); // Same normalized result expected in different locales. } }
public void UriUnescapingDataString_Unicode_SurrogatePair() { using (ThreadCultureChange iriHelper = new ThreadCultureChange()) { string escapedInput = Uri.EscapeDataString(GB18030CertificationString1); string output = Uri.UnescapeDataString(escapedInput); Assert.Equal(GB18030CertificationString1, output); iriHelper.ChangeCultureInfo("zh-cn"); string outputZhCn = Uri.UnescapeDataString(escapedInput); Assert.Equal(output, outputZhCn); //Same normalized result expected in different locales. } }
public void UriUnescapingDataString_UnicodeWithIRI_Unescaped() { using (ThreadCultureChange helper = new ThreadCultureChange()) { string input = @"\u30AF"; string output = Uri.UnescapeDataString(Escape(input)); Assert.Equal(input, output); helper.ChangeCultureInfo("zh-cn"); string outputZhCn = Uri.UnescapeDataString(Escape(input)); Assert.Equal(output, outputZhCn); // Same normalized result expected in different locales. } }
private void VerifyUriNormalizationForEscapedCharacters(string uriInput) { UriComponents[] components = new UriComponents[] { UriComponents.Fragment, UriComponents.Host, UriComponents.Path, UriComponents.Port, UriComponents.Query, UriComponents.Scheme, UriComponents.UserInfo, }; using (ThreadCultureChange helper = new ThreadCultureChange()) { string[] results1 = new string[components.Length]; helper.ChangeCultureInfo(_testedLocales[0]); for (int i = 0; i < components.Length; i++) { results1[i] = EscapeUnescapeTestComponent(uriInput, components[i]); } for (int j = 1; j < _testedLocales.Length; j++) { helper.ChangeCultureInfo(_testedLocales[j]); string[] results2 = new string[components.Length]; for (int i = 0; i < components.Length; i++) { results2[i] = EscapeUnescapeTestComponent(uriInput, components[i]); } for (int i = 0; i < components.Length; i++) { Assert.Equal( 0, String.CompareOrdinal(results1[i], results2[i])); } } } }
private void MatchUTF8SequenceTest(byte[] inbytes, int numBytes) { using (ThreadCultureChange helper = new ThreadCultureChange()) { MatchUTF8SequenceOverrunTest(inbytes, numBytes, true, false); MatchUTF8SequenceOverrunTest(inbytes, numBytes, true, true); MatchUTF8SequenceOverrunTest(inbytes, numBytes, false, false); MatchUTF8SequenceOverrunTest(inbytes, numBytes, false, true); helper.ChangeCultureInfo("zh-cn"); MatchUTF8SequenceOverrunTest(inbytes, numBytes, true, false); MatchUTF8SequenceOverrunTest(inbytes, numBytes, true, true); MatchUTF8SequenceOverrunTest(inbytes, numBytes, false, false); MatchUTF8SequenceOverrunTest(inbytes, numBytes, false, true); } }
private void EscapeUnescapeAllUriComponentsInDifferentCultures(string uriInput) { UriComponents[] components = new UriComponents[] { UriComponents.AbsoluteUri, UriComponents.Fragment, UriComponents.Host, UriComponents.HostAndPort, UriComponents.HttpRequestUrl, UriComponents.KeepDelimiter, UriComponents.NormalizedHost, UriComponents.Path, UriComponents.PathAndQuery, UriComponents.Port, UriComponents.Query, UriComponents.Scheme, UriComponents.SchemeAndServer, UriComponents.SerializationInfoString, UriComponents.StrongAuthority, UriComponents.StrongPort, UriComponents.UserInfo, }; string[] results_en = new string[components.Length]; string[] results_zh = new string[components.Length]; using (ThreadCultureChange helper = new ThreadCultureChange()) { for (int i = 0; i < components.Length; i++) { results_en[i] = EscapeUnescapeTestComponent(uriInput, components[i]); } helper.ChangeCultureInfo("zh-cn"); for (int i = 0; i < components.Length; i++) { results_zh[i] = EscapeUnescapeTestComponent(uriInput, components[i]); } for (int i = 0; i < components.Length; i++) { Assert.True( 0 == String.CompareOrdinal(results_en[i], results_zh[i]), "Detected locale differences when processing UriComponents." + components[i]); } } }