File tree Expand file tree Collapse file tree 2 files changed +22
-9
lines changed Expand file tree Collapse file tree 2 files changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -1386,12 +1386,12 @@ def self.compress(str)
1386
1386
# Randomize the whitespace in a string
1387
1387
#
1388
1388
def self . randomize_space ( str )
1389
+ set = [ "\x09 " , "\x20 " , "\x0d " , "\x0a " ]
1389
1390
str . gsub ( /\s +/ ) { |s |
1390
1391
len = rand ( 50 ) +2
1391
- set = "\x09 \x20 \x0d \x0a "
1392
1392
buf = ''
1393
1393
while ( buf . length < len )
1394
- buf << set [ rand ( set . length ) , 1 ]
1394
+ buf << set . sample
1395
1395
end
1396
1396
1397
1397
buf
@@ -1582,37 +1582,37 @@ def self.rand_hostname
1582
1582
( rand ( 5 ) + 1 ) . times {
1583
1583
host . push ( Rex ::Text . rand_text_alphanumeric ( rand ( 10 ) + 1 ) )
1584
1584
}
1585
- host . push ( TLDs [ rand ( TLDs . size ) ] )
1585
+ host . push ( TLDs . sample )
1586
1586
host . join ( '.' ) . downcase
1587
1587
end
1588
1588
1589
1589
# Generate a state
1590
1590
def self . rand_state ( )
1591
- States [ rand ( States . size ) ]
1591
+ States . sample
1592
1592
end
1593
1593
1594
1594
# Generate a surname
1595
1595
def self . rand_surname
1596
- Surnames [ rand ( Surnames . size ) ]
1596
+ Surnames . sample
1597
1597
end
1598
1598
1599
1599
# Generate a name
1600
1600
def self . rand_name
1601
1601
if rand ( 10 ) % 2 == 0
1602
- Names_Male [ rand ( Names_Male . size ) ]
1602
+ Names_Male . sample
1603
1603
else
1604
- Names_Female [ rand ( Names_Female . size ) ]
1604
+ Names_Female . sample
1605
1605
end
1606
1606
end
1607
1607
1608
1608
# Generate a male name
1609
1609
def self . rand_name_male
1610
- Names_Male [ rand ( Names_Male . size ) ]
1610
+ Names_Male . sample
1611
1611
end
1612
1612
1613
1613
# Generate a female name
1614
1614
def self . rand_name_female
1615
- Names_Female [ rand ( Names_Female . size ) ]
1615
+ Names_Female . sample
1616
1616
end
1617
1617
1618
1618
# Generate a random mail address
Original file line number Diff line number Diff line change 114
114
end
115
115
end
116
116
117
+ context ".randomize_space" do
118
+ let ( :sample_text ) { "The quick brown sploit jumped over the lazy A/V" }
119
+ let ( :spaced_text ) { described_class . randomize_space ( sample_text ) }
120
+ it "should return a string with at least one new space characater" do
121
+ spaced_text . should match /\x09 \x0d \x0a /
122
+ end
123
+
124
+ it "should not otherwise be mangled" do
125
+ normalized_text = spaced_text . gsub ( /[\x20 \x09 \x0d \x0a ]+/m , " " )
126
+ normalized_text . should eq ( sample_text )
127
+ end
128
+ end
129
+
117
130
end
118
131
end
119
132
You can’t perform that action at this time.
0 commit comments