diff --git a/lib/miq_expression/field.rb b/lib/miq_expression/field.rb index 759d402b839..f0030c46a97 100644 --- a/lib/miq_expression/field.rb +++ b/lib/miq_expression/field.rb @@ -31,10 +31,12 @@ def date? end def self.is_field?(field) - if field.kind_of?(String) - match = FIELD_REGEX.match(field) - match.present? && match[:model_name].safe_constantize.present? - end + return false unless field.kind_of?(String) + match = FIELD_REGEX.match(field) + return false unless match + model = match[:model_name].safe_constantize + return false unless model + !!(model < ApplicationRecord) end def datetime? diff --git a/spec/lib/miq_expression/field_spec.rb b/spec/lib/miq_expression/field_spec.rb index 35925cea31a..638a3626f6c 100644 --- a/spec/lib/miq_expression/field_spec.rb +++ b/spec/lib/miq_expression/field_spec.rb @@ -232,6 +232,7 @@ it "does not detect a string to looks like a field but isn't" do expect(MiqExpression::Field.is_field?("NetworkManager-team")).to be_falsey + expect(described_class.is_field?("ManageIQ-name")).to be(false) end end end