-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Add exception on failed port string parsing in BindingAddress.cs Resolves #24384 #63135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Applying suggestion to match linting. Co-authored-by: Günther Foidl <[email protected]>
Adding additional help message. Co-authored-by: Günther Foidl <[email protected]>
@gfoidl I added some tests in the PR as well. |
I think there's still an extra ' at the end after allowed. Perhaps a . or nothing to end the message? Co-authored-by: Günther Foidl <[email protected]>
Additional changes will be required to handle NamedPipes. It is odd that the previous code worked as it set a port with named pipes, so will require further research. |
While reviewing the test failures, I identified a pre-existing issue in the code. The port parsing code is wrapped in an if statement checking it is not a unix pipe, but fails to check if it is not a named pipe as well. This allowed named pipes to enter the port parsing code block, which combined with my earlier change, resulted in the thrown FormatException. Since named pipes do not have ports and therefore do not need to parse port numbers, I've added the not named pipe condition to the if statement to skip the code block for named or unix pipes. |
Latest change fixes support for IPv6 [::1] binding. Test cases had non-bindable addresses marked as valid, so those were removed. For people looking simply to parse a Uri, they should use Uri.TryCreate(), not BindingAddress.Parse() as it infers a valid, bindable address, not just a valid uri. |
Add exception on failed port string parsing in BindingAddress.cs
This PR adds a FormatException in the BindingAddress.cs when an invalid portString cannot be parsed as int.
Description
Users have reported that when passing address strings containing invalid port strings is passed into BindingAddress.Parse(), instead of throwing an exception or generating a warning, the invalid port string is ignored, and the default ports (80/443) are applied. Invalid address strings such as "https://*:{abc}" should throw a FormatException due to the invalid port value 'abc' similar to how FormatExceptions are thrown for invalid hostnames.
Fixes #24384