From 31a39f6714eada9b8b508c93ec422db6ff5ff067 Mon Sep 17 00:00:00 2001 From: Gabriel Nagy Date: Thu, 2 Apr 2026 12:04:19 +0300 Subject: [PATCH] Fix Columnar sort priority crash after mutation When a setter like extensions= clears @__sort_priority and the container is not fully loaded, Columnar#update_sort_priority reads bits from nil instead of recomputing. Fall back to super in that case. Signed-off-by: Gabriel Nagy --- lib/mime/type/columnar.rb | 2 +- test/test_mime_types_class.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/mime/type/columnar.rb b/lib/mime/type/columnar.rb index 7006fab..2d3fa43 100644 --- a/lib/mime/type/columnar.rb +++ b/lib/mime/type/columnar.rb @@ -54,7 +54,7 @@ def encode_with(coder) # :nodoc: end def update_sort_priority - if @container.__fully_loaded? + if @container.__fully_loaded? || @__sort_priority.nil? super else obsolete = (@__sort_priority & (1 << 7)) != 0 diff --git a/test/test_mime_types_class.rb b/test/test_mime_types_class.rb index 05494dd..4904c4c 100644 --- a/test/test_mime_types_class.rb +++ b/test/test_mime_types_class.rb @@ -103,6 +103,13 @@ def setup assert_includes MIME::Types.type_for("xtxt"), "text/plain" end + it "sorts correctly after modifying type extensions" do + a = MIME::Types["text/plain"].first + b = MIME::Types["image/jpeg"].first + a.add_extensions("sort-test") + assert_equal 2, [a, b].sort.length + end + it "handles newline characters correctly" do assert_includes MIME::Types.type_for("test.pdf\n.txt"), "text/plain" assert_includes MIME::Types.type_for("test.txt\n.pdf"), "application/pdf"