You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
UriBuilder should percent-encode its UserName or Password properties #74662
Constructing a URI with the UriBuilder class should produce valid URIs when setting valid UserName and/or Password properties. Instead, an UriFormatException is thrown if the user name or password contains a character that should be percent-encoded.
It should be the responsibility of the UriBuilder to properly percent-encode characters in the UserName and/or Password properties. Note that the documentation of the properties does not mention anything about percent-escaping so by the principle of least astonishment I'd expect the UriBuilder to properly escape what needs to be escaped.
Activity
MihaZupan commentedon Aug 29, 2022
I agree that throwing when accessing
builder.Uriis odd and the exception message is not ideal.The spec defines user-info as
unreserved / pct-encoded / sub-delims / ":".The problematic characters are
"/" / "\" / "?" / "#" / "@"(gen-delimsexcluding[and]).Blindly encoding the input (
Uri.EscapeDataString) would be a breaking change, as we would start double-encoding already-encoded values.The options here are:
Uri.EscapeDataStringon the input)UserNameorPasswordare setGiven that the implementation already encodes some characters (e.g. spaces or non-encoded non-ASCII), I am leaning towards the latter.
Example replacement code that you could use (or that could live in UriBuilder)
karelz commentedon Aug 30, 2022
Triage: Should be fairly straightforward (see code in #74662 (comment) - bunch of Replace calls), but not critical.
Encode UserName value in UriBuilder (Issue #74662) (#74953)