diff --git a/lib/rex/text.rb b/lib/rex/text.rb index d74dd21e98..ed759eb0cb 100644 --- a/lib/rex/text.rb +++ b/lib/rex/text.rb @@ -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 diff --git a/spec/lib/rex/text_spec.rb b/spec/lib/rex/text_spec.rb index 75119fb8e1..ddf4fa04a3 100644 --- a/spec/lib/rex/text_spec.rb +++ b/spec/lib/rex/text_spec.rb @@ -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