http-extensions icon indicating copy to clipboard operation
http-extensions copied to clipboard

Key sort should be stable

Open ricea opened this issue 5 months ago • 1 comments

https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-no-vary-search-03#section-6-2.8.2.2.1 says

  1. Set searchParamsA to the result of sorting searchParamsA in ascending order with keyLessThan.
  2. Set searchParamsB to the result of sorting searchParamsB in ascending order with keyLessThan.

I think it should explicitly mention that the sorts should be stable, otherwise implementations might accidentally change the order of multiple values with the same key, resulting in erroneous matches or mismatches.

It could either say "sorting ... in ascending order with keyLessThan preserving the existing order of pairs with identical keys" or just "stably sorting".

Chromium is already using a stable sort in practice.

ricea avatar Sep 29 '25 14:09 ricea

I think the real problem here is that the document says it's using the Infra Standard and uses inline references for algorithms used from that standard, but then doesn't actually do it for this operation. https://infra.spec.whatwg.org/#list-sort-in-ascending-order is quite clear this is supposed to be stable.

annevk avatar Sep 29 '25 14:09 annevk