Skip to content

Commit 1071c7e

Browse files
authored
Merge pull request rapid7#20127 from bcoles/lib-msf-core-option_container
Msf::OptionContainer: Replace `.sorted` Array attribute with `self.sort`
2 parents c9fb08b + ae65bb3 commit 1071c7e

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

lib/msf/core/option_container.rb

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,18 @@ class OptionContainer < Hash
5050
# as necessary.
5151
#
5252
def initialize(opts = {})
53-
self.sorted = []
5453
self.groups = {}
5554

5655
add_options(opts)
5756
end
5857

58+
#
59+
# Return the sorted array of options.
60+
#
61+
def sorted
62+
self.sort
63+
end
64+
5965
#
6066
# Return the value associated with the supplied name.
6167
#
@@ -116,10 +122,6 @@ def has_evasion_options?
116122
# @param [String] name the option name
117123
def remove_option(name)
118124
delete(name)
119-
sorted.each_with_index { |e, idx|
120-
sorted[idx] = nil if (e[0] == name)
121-
}
122-
sorted.delete(nil)
123125
end
124126

125127
#
@@ -170,9 +172,6 @@ def add_option(option, name = nil, owner = nil, advanced = false, evasion = fals
170172
option.owner = owner
171173

172174
self.store(option.name, option)
173-
174-
# Re-calculate the sorted list
175-
self.sorted = self.sort
176175
end
177176

178177
#
@@ -330,18 +329,11 @@ def remove_group(group_name)
330329
groups.delete(group_name)
331330
end
332331

333-
#
334-
# The sorted array of options.
335-
#
336-
attr_reader :sorted
337-
338332
# @return [Hash<String, Msf::OptionGroup>]
339333
attr_reader :groups
340334

341335
protected
342336

343-
attr_writer :sorted # :nodoc:
344-
345337
attr_writer :groups
346338
end
347339

lib/msf/ui/console/module_option_tab_completion.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def tab_complete_option_names(mod, str, words)
7878
return res
7979
end
8080

81-
mod.options.sorted.each do |e|
81+
mod.options.each do |e|
8282
name, _opt = e
8383
res << name
8484
end
@@ -101,7 +101,7 @@ def tab_complete_option_names(mod, str, words)
101101
if ((mod.exploit? || mod.evasion?) && mod.datastore['PAYLOAD'])
102102
p = framework.payloads.create(mod.datastore['PAYLOAD'])
103103
if p
104-
p.options.sorted.each do |e|
104+
p.options.each do |e|
105105
name, _opt = e
106106
res << name
107107
end
@@ -119,7 +119,8 @@ def tab_complete_option_names(mod, str, words)
119119
end
120120
end
121121
end
122-
return res
122+
123+
return res.sort
123124
end
124125

125126
#

0 commit comments

Comments
 (0)