-
Notifications
You must be signed in to change notification settings - Fork 4.9k
improve port parsing to be more resilient against trailing characters #31232
Conversation
|
@dotnet-bot test Outerloop Windows x64 Debug Build |
| { | ||
| host = value.Substring(0, separatorIndex); | ||
| if (!ushort.TryParse(value.AsSpan(separatorIndex + 1), out port)) | ||
| int endIndex = separatorIndex + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this string parsing code exist at all? Why not just convert the string to a URI and then extract the host and port portions of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was like that at some point. It did not handle well cases when the value is for example just IP (or ip + port) The other issue was handling special characters in password. So we end up breaking it to fragments on our own.
| host = value.Substring(0, separatorIndex); | ||
| if (!ushort.TryParse(value.AsSpan(separatorIndex + 1), out port)) | ||
| int endIndex = separatorIndex + 1; | ||
| // Strip any trailing characters after port num,ber. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"num,ber" -> "number"
| break; | ||
| } | ||
| endIndex += 1; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add newline after this brace.
| // Strip any trailing characters after port num,ber. | ||
| while (endIndex < value.Length) | ||
| { | ||
| if (!char.IsDigit(value[endIndex])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that char.IsDigit returns true for things other than '0'-'9'. It may not matter here other than for very esoteric cases.
…dotnet#31232) improve port parsing to be more resilient against trailing characters
…dotnet/corefx#31232) improve port parsing to be more resilient against trailing characters Commit migrated from dotnet/corefx@56d177d
Primarily covers 'http://10.30.62.64:7890/' accepted by curl.
Fixes #31326