Remove unsafe code in CreateUriInfo and fix edge-case IndexOutOfRangeExceptions #121653
+98
−113
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.
Fixes #1487
Uri parsing happens in stages:
PrivateParseMinimal- The ctor will only do minimal validation to see whether it should throwCreateUriInfo- Accessing properties will allocateUriInfoand populate some offsets of various Uri components (scheme, userinfo, host, port). This is enough to access theHost.ParseRemaining- Accessing properties likePathAndQuerywill populate the rest of the offsets and check whether the input is in the canonical form (whether we'll have to do some text changes for the properties).If the input contains non-ASCII, we'll also rebuild the string representation and do all parts as part of the ctor. While recreating the string, we're dealing with two separate offsets (into the original and into the (partial) new string).
The issue with #1487 was that we were indexing into the new string instead of the original inside
CreateUriInfo, which broke implicit files where the host got reduced in length (by removing bidi chars).This PR fixes that, and also removes the use of unsafe code in that method.
No real perf impact - MihuBot/runtime-utils#1635, MihuBot/runtime-utils#1636
As alaways, easier to review without space changes.