tmenier / Flurl

Fluent URL builder and testable HTTP client for .NET
https://flurl.dev
MIT License
4.23k stars 387 forks source link

FlurlClient.Request cannot handle ® followed by a space in query string. #717

Closed esowers closed 2 years ago

esowers commented 2 years ago

When trying to create a request containing a "®" followed by a space " ", an Argument Exception is thrown ("Cannot create a Request. Neither BaseUrl nor the first segment passed is a valid URL.".

Example

var testHttp = new Flurl.Http.Testing.HttpTest();
testHttp.ForCallsTo("http://www.example.com*").RespondWith("OK");

var client = new Flurl.Http.FlurlClient();
Url test = Url.Combine( "http://www.example.com?q=® ts");
var result = await client.Request(test).GetAsync(); // throws ArgumentException

No exception thrown

var testHttp = new Flurl.Http.Testing.HttpTest();
testHttp.ForCallsTo("http://www.example.com*").RespondWith("OK");

var client = new Flurl.Http.FlurlClient();
Url test = Url.Combine( "http://www.example.com?q=®ts"); //note the lack of a space
var result = await client.Request(test).GetAsync(); //no ArgumentException thrown

Even if you skip straight to the escaped string, the same issue occurs

With excemption

var testHttp = new Flurl.Http.Testing.HttpTest();
testHttp.ForCallsTo("http://www.example.com*").RespondWith("OK");

var client = new Flurl.Http.FlurlClient();
Url test = Url.Combine( "http://www.example.com?q=%C2%AE%20ts");
var result = await client.Request(test).GetAsync(); // throws ArgumentException

No exception thrown

var testHttp = new Flurl.Http.Testing.HttpTest();
testHttp.ForCallsTo("http://www.example.com*").RespondWith("OK");

var client = new Flurl.Http.FlurlClient();
Url test = Url.Combine( "http://www.example.com?q=%C2%AEts"); //note the lack of a space
var result = await client.Request(test).GetAsync(); //no ArgumentException thrown
tmenier commented 2 years ago

Thanks for reporting. This is definitely related to #462 so I'm closing in favor of that issue but I've added your examples to the comments. In short, this is (in my opinion) a Microsoft bug that they won't commit to fixing and I haven't determined if there's a reasonable work-around.