Bug #14017
closedHash.sort_by inconsistent between 2.2.6 and upper versions
Description
The bug occurs when sorting by a numeric value and two different keys have similar values: It is very easily demonstrated here:
enc = {"foo"=>0.9, "bar"=>1.0, "identity"=>1.0}
enc.sort_by { |_, q| -q }
# in ruby 2.2.6
#=> [["identity", 1.0], ["bar", 1.0], ["foo", 0.9]]
# in rubies > 2.2
#=> [["bar", 1.0], ["identity", 1.0], ["foo", 0.9]]
For the record, newer rubies present the correct version IMO, as the order of equivalent values shouldn't be changed based on the same value.
I looked at the ruby 2.3 release notes, but couldn't find the mention to a fix, so I can't say that this is a "behaviour change, upgrade to new" case. What I can say is that this behaviour seems to have changed in ruby 2.3 (tested also with ruby 2.2.2 and ruby 2.1.9 and can reproduce the same result as with 2.2.6).
As an example of production code which is probably returning a wrong result is rack, which uses as variation of this to select the best content encoding .
Is this something which can be backported into a possible 2.2.7, or is ruby 2.2 in maintenance mode?