Use Array#sample in randomize_space

Tod Beardsley 2014-04-01 14:08:52 -05:00
parent 2972220f60
commit 8ab03f3aeb
No known key found for this signature in database
GPG Key ID: 1EFFB682ADB9F193
2 changed files with 15 additions and 2 deletions

View File

@ -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

View File

@ -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