From 92eaa5f5f915576f67d90d5fa921ca287703af9e Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Tue, 5 Nov 2019 20:06:48 -0800 Subject: or we can actually fix it on the fly rely on identifying an integer value or a string that converts to an integer (out of paranoia) vs. a string which is a sort argument to be able to delete the search argument. this makes the code backwards compatible with chef 11 Signed-off-by: Lamont Granquist --- lib/chef/search/query.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/chef/search/query.rb b/lib/chef/search/query.rb index 46dedd33f8..c0cdc49b71 100644 --- a/lib/chef/search/query.rb +++ b/lib/chef/search/query.rb @@ -125,6 +125,19 @@ class Chef return {} if args.empty? return args.first if args.first.is_a?(Hash) + first_arg_is_integer = + begin + Integer(args[0]) + true + rescue + false + end + + if args[0].is_a?(String) && !first_arg_is_integer + Chef::Log.warn "Sort argument to search API is ignored and should be removed: #{args[0]}" + args.shift + end + args_h = {} args_h[:start] = args[0] if args[0] args_h[:rows] = args[1] -- cgit v1.2.1