Replace the core of the text generation methods; previously, these could result in an oddball string result that would not auto-convert into ASCII-8BIT. Looks like a strange corner case in Ruby 1.9
git-svn-id: file:///home/svn/framework3/trunk@9254 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
aedf63c063
commit
5f23151c22
|
@ -463,7 +463,7 @@ module Text
|
|||
coords = []
|
||||
(1 << str.size).times { |i| coords << ("%0#{str.size}b" % i) }
|
||||
mixed = []
|
||||
coords.each do |coord|
|
||||
coords.each do |coord|
|
||||
c = coord.scan(/./).map {|x| x.to_i}
|
||||
this_str = ""
|
||||
c.each_with_index { |d,i| this_str << letters[i][d] }
|
||||
|
@ -626,22 +626,11 @@ module Text
|
|||
|
||||
# Base text generator method
|
||||
def self.rand_base(len, bad, *foo)
|
||||
# Remove restricted characters
|
||||
(bad || '').split('').each { |c| foo.delete(c) }
|
||||
|
||||
# Return nil if all bytes are restricted
|
||||
return nil if foo.length == 0
|
||||
|
||||
buff = ""
|
||||
|
||||
# Generate a buffer from the remaining bytes
|
||||
if foo.length >= 256
|
||||
len.times { buff << Kernel.rand(256) }
|
||||
else
|
||||
len.times { buff << foo[ rand(foo.length) ] }
|
||||
end
|
||||
|
||||
return buff
|
||||
cset = (foo.join.unpack("C*") - bad.to_s.unpack("C*")).uniq
|
||||
return if cset.length == 0
|
||||
outp = []
|
||||
len.times { outp << cset[rand(cset.length)] }
|
||||
outp.pack("C*")
|
||||
end
|
||||
|
||||
# Generate random bytes of data
|
||||
|
|
Loading…
Reference in New Issue