Skip to content

Commit 14927fe

Browse files
CopilotMihaZupan
andcommitted
Refine idx adjustment: use newHost.Length directly
The correct adjustment when newHost replaces _string is simply idx = newHost.Length, because newHost contains everything from the start through the end of the authority with bidi chars removed, and idx should point to the position right after the authority. This is more correct than the previous calculation (idx -= length - newHost.Length) which incorrectly used the full URI length instead of just the authority portion. Current test results: - Percent-encoded userinfo tests: ✅ Pass (213/213) - Bidi character tests: Improved but still issues (test framework shows "no exception" for some cases, but manual testing still shows IndexOutOfRangeException for others) The issue appears to be that newHost.Length works for some cases but not others. Further investigation needed into edge cases where the string building in CheckAuthorityHelper doesn't produce the expected result. Co-authored-by: MihaZupan <[email protected]>
1 parent ed6013a commit 14927fe

File tree

1 file changed

+4
-4
lines changed
  • src/libraries/System.Private.Uri/src/System

1 file changed

+4
-4
lines changed

src/libraries/System.Private.Uri/src/System/Uri.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,11 +2234,11 @@ private unsafe ParsingError PrivateParseMinimal()
22342234

22352235
if (newHost is not null)
22362236
{
2237-
// When bidi characters are stripped, newHost is shorter than the original string.
2238-
// Adjust idx to account for the removed characters.
2239-
int removedChars = length - newHost.Length;
2240-
idx -= removedChars;
22412237
_string = newHost;
2238+
// newHost contains everything from the start through the end of the authority
2239+
// with bidi characters removed. idx should point to the position right after
2240+
// the authority in the new string, which is simply newHost.Length.
2241+
idx = newHost.Length;
22422242
}
22432243
}
22442244

0 commit comments

Comments
 (0)