From 3eb85f92869e5d6fa8588f2cbf69eeb3570437c2 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 3 Jan 2024 16:27:00 -0800 Subject: [PATCH 1/2] Add failing test for box collection sorting --- test/unit/vagrant/box_collection_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/unit/vagrant/box_collection_test.rb b/test/unit/vagrant/box_collection_test.rb index 16eb6b2f3..ddb0cc8fa 100644 --- a/test/unit/vagrant/box_collection_test.rb +++ b/test/unit/vagrant/box_collection_test.rb @@ -111,6 +111,17 @@ describe Vagrant::BoxCollection, :skip_windows, :bsdtar do end.not_to raise_error end + context "with architectures defined" do + before do + environment.box3("foo-VAGRANTSLASH-bar", "1.0", :virtualbox, architecture: :arm64) + end + + it "should sort boxes by name" do + result = subject.all.map(&:first).uniq + expect(result).to eq(["bar", "foo", "foo/bar", "foo:colon"]) + end + end + it "should sort boxes by version" do box_list = subject.all.find_all do |box_info| box_info[0] == "foo" && box_info[2].to_s == "virtualbox" From b741d8332bff060878ce915a73b9038285e64bf0 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 3 Jan 2024 16:27:25 -0800 Subject: [PATCH 2/2] Fix box collection sorting with mixed architecture When the box collection consists of a mix of entries with architecture information and without architecture information, ensure the values are a common type so sorting does not result in an error. --- lib/vagrant/box_collection.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/box_collection.rb b/lib/vagrant/box_collection.rb index 117d31f3a..6666edae8 100644 --- a/lib/vagrant/box_collection.rb +++ b/lib/vagrant/box_collection.rb @@ -299,7 +299,12 @@ module Vagrant end # Sort the list to group like providers and properly ordered versions results.sort_by! do |box_result| - [box_result[0], box_result[2], Gem::Version.new(box_result[1]), box_result[3]] + [ + box_result[0], + box_result[2], + Gem::Version.new(box_result[1]), + box_result[3] || :"" + ] end results end