Skip to content

Commit d66779b

Browse files
David MaloneyDavid Maloney
authored andcommitted
OptString specs and better validation
1 parent d6f2b28 commit d66779b

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

lib/msf/core/option_container.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def normalize(value)
173173

174174
def valid?(value=self.value)
175175
value = normalize(value)
176+
return false unless value.kind_of?(String) or value.kind_of?(NilClass)
176177
return false if empty_required_value?(value)
177178
return super
178179
end

spec/file_fixtures/string_list.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
foo
2+
bar
3+
baz
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding:binary -*-
2+
3+
require 'spec_helper'
4+
require 'msf/core/option_container'
5+
6+
describe Msf::OptString do
7+
valid_values = [
8+
{ :value => 'foo', :normalized => 'foo' },
9+
{ :value => "file:#{File.expand_path('string_list.txt',FILE_FIXTURES_PATH)}",:normalized => "foo\nbar\nbaz" },
10+
]
11+
invalid_values = [
12+
# Non-string values
13+
{ :value => true},
14+
{ :value => 5 },
15+
{ :value => []},
16+
{ :value => [1,2]},
17+
{ :value => {}},
18+
]
19+
20+
it_behaves_like "an option", valid_values, invalid_values, 'string'
21+
end

0 commit comments

Comments
 (0)