From 1e25ed3d075a3e13e3067fa709f57d5f4f186a05 Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Thu, 20 Feb 2025 15:03:18 -0500 Subject: [PATCH] Numerics shouldn't be tested for ".bytes" like suffix Symbols or other non-strings should be converted to strings before testing the regex. Fixes https://github.com/ManageIQ/manageiq-ui-classic/issues/9357 --- lib/miq_expression.rb | 3 ++- spec/lib/miq_expression_spec.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/miq_expression.rb b/lib/miq_expression.rb index 4f74c199ebf..31ab66d4c15 100644 --- a/lib/miq_expression.rb +++ b/lib/miq_expression.rb @@ -805,8 +805,9 @@ def self.quote_human(val, typ) case typ&.to_sym when :integer, :decimal, :fixnum, :float return val.to_i unless val.to_s.number_with_method? || typ == :float + return val if val.kind_of?(Numeric) - if val =~ /^([0-9.,]+)\.([a-z]+)$/ + if val.to_s =~ /^([0-9.,]+)\.([a-z]+)$/ val, sfx = $1, $2 if sfx.ends_with?("bytes") && FORMAT_BYTE_SUFFIXES.key?(sfx.to_sym) "#{val} #{FORMAT_BYTE_SUFFIXES[sfx.to_sym]}" diff --git a/spec/lib/miq_expression_spec.rb b/spec/lib/miq_expression_spec.rb index da1634a6104..74afcd2497f 100644 --- a/spec/lib/miq_expression_spec.rb +++ b/spec/lib/miq_expression_spec.rb @@ -2423,6 +2423,16 @@ expect(exp.to_human).to eq("COUNT OF Snaps > 1") end + it "generates a human readable string for a numeric FIELD value expression" do + exp = MiqExpression.new(">"=>{"field"=>"Vm.hardware.volumes-free_space_percent", "value"=>75}) + expect(exp.to_human).to eq("VM and Instance.Hardware.Volumes : Free Space Percent > 75") + end + + it "generates a human readable string for a symbol FIELD value expression" do + exp = MiqExpression.new(">" => {"field" => "Vm-allocated_disk_storage", "value" => :"5.megabytes"}) + expect(exp.to_human).to eq("VM and Instance : Allocated Disk Storage > 5 MB") + end + context "TAG type expression" do before do # tags contain the root tenant's name