From b35d53bd02723068dc04563a6a4561d1cbdb959e Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Sat, 5 Aug 2017 02:22:04 -0500 Subject: [PATCH] code cleanup in opt_int while we're here --- lib/msf/core/opt_int.rb | 50 +++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/lib/msf/core/opt_int.rb b/lib/msf/core/opt_int.rb index 047c9ab05f..0c5191d04b 100644 --- a/lib/msf/core/opt_int.rb +++ b/lib/msf/core/opt_int.rb @@ -1,36 +1,28 @@ # -*- coding: binary -*- module Msf - -### -# -# Integer option. -# -### -class OptInt < OptBase - def type - return 'integer' - end - - def normalize(value) - if value.to_s.match(/^0x[a-fA-F\d]+$/) - value.to_i(16) - elsif value.present? - value.to_i - else - nil - end - end - - def valid?(value, check_empty: true) - return false if check_empty && empty_required_value?(value) - - if value.present? and not value.to_s.match(/^0x[0-9a-fA-F]+$|^-?\d+$/) - return false + ### + # + # Integer option. + # + ### + class OptInt < OptBase + def type + 'integer' end - return super + def normalize(value) + if value.to_s.match?(/^0x[a-fA-F\d]+$/) + value.to_i(16) + elsif value.present? + value.to_i + end + end + + def valid?(value, check_empty: true) + return false if check_empty && empty_required_value?(value) + return false if value.present? && !value.to_s.match?(/^0x[0-9a-fA-F]+$|^-?\d+$/) + super + end end end - -end