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 = []
|
coords = []
|
||||||
(1 << str.size).times { |i| coords << ("%0#{str.size}b" % i) }
|
(1 << str.size).times { |i| coords << ("%0#{str.size}b" % i) }
|
||||||
mixed = []
|
mixed = []
|
||||||
coords.each do |coord|
|
coords.each do |coord|
|
||||||
c = coord.scan(/./).map {|x| x.to_i}
|
c = coord.scan(/./).map {|x| x.to_i}
|
||||||
this_str = ""
|
this_str = ""
|
||||||
c.each_with_index { |d,i| this_str << letters[i][d] }
|
c.each_with_index { |d,i| this_str << letters[i][d] }
|
||||||
|
@ -626,22 +626,11 @@ module Text
|
||||||
|
|
||||||
# Base text generator method
|
# Base text generator method
|
||||||
def self.rand_base(len, bad, *foo)
|
def self.rand_base(len, bad, *foo)
|
||||||
# Remove restricted characters
|
cset = (foo.join.unpack("C*") - bad.to_s.unpack("C*")).uniq
|
||||||
(bad || '').split('').each { |c| foo.delete(c) }
|
return if cset.length == 0
|
||||||
|
outp = []
|
||||||
# Return nil if all bytes are restricted
|
len.times { outp << cset[rand(cset.length)] }
|
||||||
return nil if foo.length == 0
|
outp.pack("C*")
|
||||||
|
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generate random bytes of data
|
# Generate random bytes of data
|
||||||
|
|
Loading…
Reference in New Issue