tmenier / Flurl

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

Url object doesn't sort params on equality check #743

Closed bazarniy closed 1 year ago

bazarniy commented 1 year ago

Hi there!

Please check this code: var expectedTrueButWasFalse = new Url("/xxx?x=1&y=2").Equals(new Url("/xxx?y=2&x=1"));

Logically it is same urls, but they are not equals. I think query params should be ordered by name in equality check to use it in test assertions for example. Or there should be custom method for this type of check.

bazarniy commented 1 year ago

Or you can add extension method public Url SortQueryParams(this Url url)

tmenier commented 1 year ago

I'm going to have to disagree on a few points:

  1. This isn't a bug.
  2. "Logically it is same urls..." I disagree. Many server-side web frameworks (such as ASP.NET Core) don't care about parameter order, but there's no standard dictating that URI query strings x=1&y=2 and y=2&x=1 are equivalent.
  3. "Or you can add extension method" I don't believe this feature is broadly useful enough to bake into the library, but it's a fine idea to add to your application if you find it useful.