Use Array#sample in randomize_space
parent
2972220f60
commit
8ab03f3aeb
|
@ -1386,12 +1386,12 @@ module Text
|
|||
# Randomize the whitespace in a string
|
||||
#
|
||||
def self.randomize_space(str)
|
||||
set = ["\x09", "\x20", "\x0d", "\x0a"]
|
||||
str.gsub(/\s+/) { |s|
|
||||
len = rand(50)+2
|
||||
set = "\x09\x20\x0d\x0a"
|
||||
buf = ''
|
||||
while (buf.length < len)
|
||||
buf << set[rand(set.length),1]
|
||||
buf << set.sample
|
||||
end
|
||||
|
||||
buf
|
||||
|
|
|
@ -114,6 +114,19 @@ describe Rex::Text do
|
|||
end
|
||||
end
|
||||
|
||||
context ".randomize_space" do
|
||||
let (:sample_text) { "The quick brown sploit jumped over the lazy A/V" }
|
||||
let (:spaced_text) { described_class.randomize_space(sample_text) }
|
||||
it "should return a string with at least one new space characater" do
|
||||
spaced_text.should match /\x09\x0d\x0a/
|
||||
end
|
||||
|
||||
it "should not otherwise be mangled" do
|
||||
normalized_text = spaced_text.gsub(/[\x20\x09\x0d\x0a]+/m, " ")
|
||||
normalized_text.should eq(sample_text)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue