URL encoding and decoding: retarget net10.0, add UrlEncoder and Uri behaviour tests - #2163
Open
vladimir-pecanac-main wants to merge 2 commits into
Open
Conversation
…behaviour tests - Retarget UrlEncodingAndDecoding and Tests from net7.0 to net10.0. - Bump test packages: Microsoft.NET.Test.Sdk 18.9.0, MSTest.TestAdapter and MSTest.TestFramework 4.3.3, coverlet.collector 10.0.1. Replace the obsolete DataTestMethod attribute with TestMethod (MSTEST0044). - Add the UrlEncoder.Default.Encode() example to Program.cs and a test asserting its exact output, plus a value-level encoding line showing the shape real code should use. - Add tests for Uri.EscapeDataString on a 100,000-character string (no length limit on modern .NET), on the encodeURIComponent-safe characters, and for the Uri constructor with a bare path and with a protocol-relative address.
new Uri("/foo") throws UriFormatException on Windows but parses as the
absolute file URI file:///foo on Unix, where a bare path is a rooted local
path. The test now asserts the real behaviour on each platform instead of the
Windows one everywhere. new Uri("//example.com") is unchanged: it yields
file://example.com/ on both.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Updates the
aspnetcore-features/UrlEncodingAndDecodingsample for the article refresh.net7.0tonet10.0.Microsoft.NET.Test.Sdk18.9.0,MSTest.TestAdapterandMSTest.TestFramework4.3.3,coverlet.collector10.0.1. The obsoleteDataTestMethodattribute is replaced withTestMethod(MSTEST0044), so the build is warning-free.UrlEncoder.Default.Encode()example toProgram.cswith a test asserting its exact output, and a value-level encoding line showing the shape real code should use (the existing examples encode a whole URL, which is good for comparing encoders and wrong as a pattern to copy).Uri.EscapeDataString()on a 100,000-character string, on theencodeURIComponent-safe characters!'()*~, and for theUriconstructor with a bare path (/foo) and with a protocol-relative address (//example.com).Build and test locally, SDK 10.0.302, Windows:
Console output:
On the two
Uriconstructor testsThe two literals do not behave the way they are usually described, and they do not behave the same way as each other.
new Uri("//example.com")does not throw on either platform. It parses the leading double slash as a host and yields the absolute file URIfile://example.com/, andUri.TryCreate(..., UriKind.Absolute, out _)reports success. Confirmed on Windows locally and on ubuntu in CI, where the same assertions pass unchanged.new Uri("/foo")is platform-dependent. It throwsUriFormatExceptionon Windows, but on Unix a bare path is a rooted local path, so it parses as the absolute file URIfile:///foo. The first CI run on this branch asserted the Windows outcome everywhere and failed on ubuntu with "Expected exception of exact type UriFormatException but no exception was thrown", which is how the difference was found; the test now asserts each platform's real behaviour and both legs are green.UriKind.Relativebehaves the same everywhere and is asserted outside the platform branch.